首先让我说,我对完全不同的方法持开放态度。
我有这样的 iframe:
<div id="testloadlogin">
<iframe src="../security/login.aspx" width="400" height="500"
scrolling="auto" frameborder="1">
[Your user agent does not support frames or is currently configured
not to display frames. However, you may visit
<a href="../security/login.aspx">the related document.</a>]
</iframe>
</div>
用 iframe 加载的页面有一个名为 loginInnerBox 的 div。我只想显示 loginInnerBox 和其中的所有内容。
关于如何做到这一点有什么想法吗?我正在考虑使用某种 Jquery 或 javascript 来删除 iframe 加载的页面上的所有其他内容,但不确定如何访问它......
需要说明的是,我希望页面上 iframe 之外的所有内容都保持不变。我想要等同于说 $.('teSTLoadlogin').load('../security/login.aspx' #loginInnerBox) 这只会获取 loginInnerBox 的 html 并将其放在 teSTLoadlogin div 中。但是,我需要来自 iframe 支持的其他页面的后端处理,而不是 Jquery 加载。
iframe加载的页面标记为
<body>
<div>
</div>.......
<div class="AspNet-Login" id="ctl00_CLPMainContent_Login1">
<div id="loginInnerBox">
<div id="loginCreds">
<table>
</table>
</div>
</div>
</div>
<div>
</div>....
</body>
您还需要更多信息吗?
我试过了,没有效果:
<div class="ui-corner-all" id="RefRes">
<div id="testloadlogin">
<iframe onload="javascript:loadlogin()" id="loginiframe" src="../security/login.aspx"
scrolling="auto" frameborder="1">
[Your user agent does not support frames or is currently configured
not to display frames. However, you may visit
<a href="../security/login.aspx">the related document.</a>]
</iframe>
</div>
</div>
<script type="text/javascript">
function loadlogin() {
$('<body>*', this.contentWindow.document).not('#ctl00_CLPMainContent_Login1').hide();
}
</script>
最佳答案
使用 jQuery,您不仅可以加载 URL 的内容,还可以从该 URL 中加载特定的 CSS 选择器。这将是一种更简洁的方法。就像这样。
$("#area").load("something.html #content");
关于javascript - 在 iframe 中仅显示一个 div(javascript、JQuery...),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4086876/