Javascript 隐藏不带div或class的JS元素

Javascript 隐藏不带div或class的JS元素,javascript,dynamics-crm-2011,Javascript,Dynamics Crm 2011,我试图隐藏SSRS报告的工具栏 我需要使用JS有一个特定的原因(报告将包含在CRM 2011仪表板中,我想从报告中删除工具栏。由于报告参数不起作用,我导入了报告控制解决方案,我正在编辑使用JS的查看器)。查看器是一个Html页面,将报表嵌入为IFrame。 生成的Html代码是: <table id="reportViewer_fixedTable" cellspacing="0" cellpadding="0" style="table-layout:fixed;width:100%;h

我试图隐藏SSRS报告的工具栏

我需要使用JS有一个特定的原因(报告将包含在CRM 2011仪表板中,我想从报告中删除工具栏。由于报告参数不起作用,我导入了报告控制解决方案,我正在编辑使用JS的查看器)。查看器是一个Html页面,将报表嵌入为IFrame。 生成的Html代码是:

<table id="reportViewer_fixedTable" cellspacing="0" cellpadding="0" style="table-layout:fixed;width:100%;height:100%;">
    <tbody>
        <tr style="background-color:#C4DDFF;"> … </tr>
        <tr id="ParametersRowreportViewer" style="display:none;"> … </tr>
        <tr style="height:6px;font-size:2pt;display:none;"> … </tr>
        <tr>
我应该选择表reportViewer_fixedTable,我可以这样做,然后选择tbody元素,然后选择第四个tr。 有办法吗?可能没有jQuery。

案例:无Iframe 选择元素

作为jQuery选择器:

var selected;
selected = jQuery('#reportViewer_fixedTable');
… 
selected = jQuery('#reportViewer_fixedTable tbody');
…
selected = jQuery('#reportViewer_fixedTable tr:nth-child(4)');
var selected;
selected = document.querySelector('#reportViewer_fixedTable');
…
selected = document.querySelector('#reportViewer_fixedTable tbody');
…
selected = document.querySelector('#reportViewer_fixedTable tr:nth-child(4)');
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  <table id="reportViewer_fixedTable" cellspacing="0" cellpadding="0" style="table-layout:fixed;width:100%;height:100%;">
    <tbody>
        <tr style="background-color:#C4DDFF;"> <td>1</td> </tr>
        <tr id="ParametersRowreportViewer" style="display:none;"><td>2</td> </tr>
        <tr style="height:6px;font-size:2pt;display:none;"> <td>3</td> </tr>
        <tr><td>FourthTR</td></tr>
    </tbody>
</table>
</body>
</html>
$(function(){
console.log( $('#reportViewer_fixedTable tbody tr:nth-child(4) td:nth-child(1)').text());


  $('#reportViewer_fixedTable tbody tr:nth-child(4) td:nth-child(1)').addClass('FourthTR');
  $('.FourthTR').hide();
});
使用以下选项隐藏所选内容:

selected.css('display', 'none');
或不带jQuery的现代浏览器:

var selected;
selected = jQuery('#reportViewer_fixedTable');
… 
selected = jQuery('#reportViewer_fixedTable tbody');
…
selected = jQuery('#reportViewer_fixedTable tr:nth-child(4)');
var selected;
selected = document.querySelector('#reportViewer_fixedTable');
…
selected = document.querySelector('#reportViewer_fixedTable tbody');
…
selected = document.querySelector('#reportViewer_fixedTable tr:nth-child(4)');
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  <table id="reportViewer_fixedTable" cellspacing="0" cellpadding="0" style="table-layout:fixed;width:100%;height:100%;">
    <tbody>
        <tr style="background-color:#C4DDFF;"> <td>1</td> </tr>
        <tr id="ParametersRowreportViewer" style="display:none;"><td>2</td> </tr>
        <tr style="height:6px;font-size:2pt;display:none;"> <td>3</td> </tr>
        <tr><td>FourthTR</td></tr>
    </tbody>
</table>
</body>
</html>
$(function(){
console.log( $('#reportViewer_fixedTable tbody tr:nth-child(4) td:nth-child(1)').text());


  $('#reportViewer_fixedTable tbody tr:nth-child(4) td:nth-child(1)').addClass('FourthTR');
  $('.FourthTR').hide();
});
并隐藏:

selected.style.display = 'none';
案例:Iframe中的内容 iframe可能有问题,因为它可能是沙盒,或者内容可能来自不同的域。这可能导致XSS冲突,在您的情况下,这可能是不可修复的

不管怎样,我们走吧:

//Select the first iframe (which might not be the right one in your case);
var elem = document.querySelector('iframe'); 

//And put it's body in a variable. We use the querySelector from the body 
//of the iframe.
var ibody = elem.contentWindow.document.body;

var table = ibody.querySelector('#reportViewer_fixedTable');
var tbody = ibody.querySelector('#reportViewer_fixedTable tbody');
var fourthtr = ibody.querySelector('#reportViewer_fixedTable tr:nth-child(4)');

table.style.display = 'none';
tbody.style.display = 'none';
fourthtr.style.display = 'none';
案例:无Iframe 选择元素

作为jQuery选择器:

var selected;
selected = jQuery('#reportViewer_fixedTable');
… 
selected = jQuery('#reportViewer_fixedTable tbody');
…
selected = jQuery('#reportViewer_fixedTable tr:nth-child(4)');
var selected;
selected = document.querySelector('#reportViewer_fixedTable');
…
selected = document.querySelector('#reportViewer_fixedTable tbody');
…
selected = document.querySelector('#reportViewer_fixedTable tr:nth-child(4)');
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  <table id="reportViewer_fixedTable" cellspacing="0" cellpadding="0" style="table-layout:fixed;width:100%;height:100%;">
    <tbody>
        <tr style="background-color:#C4DDFF;"> <td>1</td> </tr>
        <tr id="ParametersRowreportViewer" style="display:none;"><td>2</td> </tr>
        <tr style="height:6px;font-size:2pt;display:none;"> <td>3</td> </tr>
        <tr><td>FourthTR</td></tr>
    </tbody>
</table>
</body>
</html>
$(function(){
console.log( $('#reportViewer_fixedTable tbody tr:nth-child(4) td:nth-child(1)').text());


  $('#reportViewer_fixedTable tbody tr:nth-child(4) td:nth-child(1)').addClass('FourthTR');
  $('.FourthTR').hide();
});
使用以下选项隐藏所选内容:

selected.css('display', 'none');
或不带jQuery的现代浏览器:

var selected;
selected = jQuery('#reportViewer_fixedTable');
… 
selected = jQuery('#reportViewer_fixedTable tbody');
…
selected = jQuery('#reportViewer_fixedTable tr:nth-child(4)');
var selected;
selected = document.querySelector('#reportViewer_fixedTable');
…
selected = document.querySelector('#reportViewer_fixedTable tbody');
…
selected = document.querySelector('#reportViewer_fixedTable tr:nth-child(4)');
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  <table id="reportViewer_fixedTable" cellspacing="0" cellpadding="0" style="table-layout:fixed;width:100%;height:100%;">
    <tbody>
        <tr style="background-color:#C4DDFF;"> <td>1</td> </tr>
        <tr id="ParametersRowreportViewer" style="display:none;"><td>2</td> </tr>
        <tr style="height:6px;font-size:2pt;display:none;"> <td>3</td> </tr>
        <tr><td>FourthTR</td></tr>
    </tbody>
</table>
</body>
</html>
$(function(){
console.log( $('#reportViewer_fixedTable tbody tr:nth-child(4) td:nth-child(1)').text());


  $('#reportViewer_fixedTable tbody tr:nth-child(4) td:nth-child(1)').addClass('FourthTR');
  $('.FourthTR').hide();
});
并隐藏:

selected.style.display = 'none';
案例:Iframe中的内容 iframe可能有问题,因为它可能是沙盒,或者内容可能来自不同的域。这可能导致XSS冲突,在您的情况下,这可能是不可修复的

不管怎样,我们走吧:

//Select the first iframe (which might not be the right one in your case);
var elem = document.querySelector('iframe'); 

//And put it's body in a variable. We use the querySelector from the body 
//of the iframe.
var ibody = elem.contentWindow.document.body;

var table = ibody.querySelector('#reportViewer_fixedTable');
var tbody = ibody.querySelector('#reportViewer_fixedTable tbody');
var fourthtr = ibody.querySelector('#reportViewer_fixedTable tr:nth-child(4)');

table.style.display = 'none';
tbody.style.display = 'none';
fourthtr.style.display = 'none';

我想你可以试着找到答案

考虑这种方法:

HTML:

var selected;
selected = jQuery('#reportViewer_fixedTable');
… 
selected = jQuery('#reportViewer_fixedTable tbody');
…
selected = jQuery('#reportViewer_fixedTable tr:nth-child(4)');
var selected;
selected = document.querySelector('#reportViewer_fixedTable');
…
selected = document.querySelector('#reportViewer_fixedTable tbody');
…
selected = document.querySelector('#reportViewer_fixedTable tr:nth-child(4)');
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  <table id="reportViewer_fixedTable" cellspacing="0" cellpadding="0" style="table-layout:fixed;width:100%;height:100%;">
    <tbody>
        <tr style="background-color:#C4DDFF;"> <td>1</td> </tr>
        <tr id="ParametersRowreportViewer" style="display:none;"><td>2</td> </tr>
        <tr style="height:6px;font-size:2pt;display:none;"> <td>3</td> </tr>
        <tr><td>FourthTR</td></tr>
    </tbody>
</table>
</body>
</html>
$(function(){
console.log( $('#reportViewer_fixedTable tbody tr:nth-child(4) td:nth-child(1)').text());


  $('#reportViewer_fixedTable tbody tr:nth-child(4) td:nth-child(1)').addClass('FourthTR');
  $('.FourthTR').hide();
});
所以,我们要做的是,我们抓取表的第四个tr,然后抓取第四个tr的第一个子项。一旦完成,我们将动态地向其中添加一个类,比如说
FourthTR
,然后使用
jQuery.hide()
隐藏该类。瞧,你完了


请参见此处的工作示例:。像往常一样,记住使用js运行

,我想您可以通过尝试查找

考虑这种方法:

HTML:

var selected;
selected = jQuery('#reportViewer_fixedTable');
… 
selected = jQuery('#reportViewer_fixedTable tbody');
…
selected = jQuery('#reportViewer_fixedTable tr:nth-child(4)');
var selected;
selected = document.querySelector('#reportViewer_fixedTable');
…
selected = document.querySelector('#reportViewer_fixedTable tbody');
…
selected = document.querySelector('#reportViewer_fixedTable tr:nth-child(4)');
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  <table id="reportViewer_fixedTable" cellspacing="0" cellpadding="0" style="table-layout:fixed;width:100%;height:100%;">
    <tbody>
        <tr style="background-color:#C4DDFF;"> <td>1</td> </tr>
        <tr id="ParametersRowreportViewer" style="display:none;"><td>2</td> </tr>
        <tr style="height:6px;font-size:2pt;display:none;"> <td>3</td> </tr>
        <tr><td>FourthTR</td></tr>
    </tbody>
</table>
</body>
</html>
$(function(){
console.log( $('#reportViewer_fixedTable tbody tr:nth-child(4) td:nth-child(1)').text());


  $('#reportViewer_fixedTable tbody tr:nth-child(4) td:nth-child(1)').addClass('FourthTR');
  $('.FourthTR').hide();
});
所以,我们要做的是,我们抓取表的第四个tr,然后抓取第四个tr的第一个子项。一旦完成,我们将动态地向其中添加一个类,比如说
FourthTR
,然后使用
jQuery.hide()
隐藏该类。瞧,你完了


请参见此处的工作示例:。像往常一样,记住使用js运行

,我认为您不需要为此使用JavaScript

如果您有权访问ReportControl解决方案和ReportViewer.aspx.cs的服务器端代码,则可以设置属性

reportViewer.ShowToolBar = false
在那个密码里

或者,如果您有权访问并可以修改查看器页面标记(ReportViewer.aspx),则可以声明式设置它:向ReportViewer控件声明添加
ShowToolBar=“false”

<rsweb:ReportViewer ID="reportViewer" runat="server" ... ShowToolBar="false">
</rsweb:ReportViewer>

我认为你不需要使用JavaScript来实现这一点

如果您有权访问ReportControl解决方案和ReportViewer.aspx.cs的服务器端代码,则可以设置属性

reportViewer.ShowToolBar = false
在那个密码里

或者,如果您有权访问并可以修改查看器页面标记(ReportViewer.aspx),则可以声明式设置它:向ReportViewer控件声明添加
ShowToolBar=“false”

<rsweb:ReportViewer ID="reportViewer" runat="server" ... ShowToolBar="false">
</rsweb:ReportViewer>


你到底想隐藏什么。详细说明一下你将在哪里放置javascript来隐藏crm仪表板中的工具栏?我已经更新了问题。请发布你的所有代码,以便我们可以看到你在哪里调用报告。另外,您导入了什么称为“报表控制”的解决方案?你能提供一个链接吗?你到底想隐藏什么。详细说明一下你将在哪里放置javascript来隐藏crm仪表板中的工具栏?我已经更新了问题。请发布你的所有代码,以便我们可以看到你在哪里调用报告。另外,您导入了什么称为“报表控制”的解决方案?你能提供一个链接吗?我不会否决你的答案,但它是“错误的”。问题是报告将在crm 2011仪表板中执行。这不起作用。考虑到表位于IFrame中,JS是否应该有所不同?user1648371:我添加了一个单独的部分来解决IFrame中的内容问题。我不会否决你的答案,但它是“错误的”。问题是报告将在crm 2011仪表板中执行。这不起作用。考虑到表位于IFrame中,JS是否应该有所不同?user1648371:我添加了一个单独的部分来解决IFrame中的内容问题。我不能使用前两个选项。我认为我们使用的是两种不同版本的SSRS:我运行报告时没有任何ReportViewer.aspx页面。我有一个Viewer.aspx。你可能是对的,但它可能是类似的东西-一个Viewer页面应该有一个Viewer控件-它是否有类似于上面显示的标记?如果页面标记不太长,你能发布它吗?还有,第三个选项呢?你能传递URL参数吗?我已经尝试了所有可能的参数,但浏览者只是忽略了它们。当我尝试粘贴呈现的查看器代码时,我收到一条“过长59507个字符”的消息,那么ASPX页面本身呢?它是否包含ReportViewer控件?我在呈现的页面中找到了许多对ReportViewerWebControlHandler的引用。我没有访问原始ASPXI的权限,无法使用前两个选项。我认为我们使用的是两种不同版本的SSRS:我运行报告时没有任何ReportViewer.aspx页面。我有一个Viewer.aspx。你可能是对的,但它可能是类似的东西-一个Viewer页面应该有一个Viewer控件-它是否有类似于上面显示的标记?如果页面标记不太长,你能发布它吗?还有,第三个选项呢?你能传递URL参数吗?我已经尝试了所有可能的参数,但浏览者只是忽略了它们。当我尝试粘贴时,有一条“过长59507个字符”的消息