是否可以编辑通过< iframe>加载的DOM元素.用jQuery? [英] Is it possible to edit DOM elements that get loaded via an <iframe> with jQuery?
问题描述
我有以下HTML代码:
I have the following HTML code:
<body>
...
<div id="users">
<iframe src="http://control.intranet/userlist.php" height="100">
</div>
...
</body>
//control.intranet/userlist.php
从我们的Intranet控制面板加载用户列表的地方.
Where the //control.intranet/userlist.php
loads a list of users from our intranet control panel.
此列表如下所示:
<div class="user">
<span class="name">Boda Cydo</span>
<span class="ip">10.42.12.2</span>
...
</div>
<div class="user">
...
</div>
...
现在,我想格式化用户列表的外观,因此我尝试使用jQuery来匹配其中的元素:
Now I want to format how the userlist looks, so I try to match elements in it with jQuery:
$("#users .name").css("background-color", "#FF0000")
但是它永远不会与单个 .name
匹配.
But it never matches a single .name
.
我什至只尝试了 $(#users").length
,它返回0.
I even tried just $("#users").length
and it returns 0.
这使我认为我无法编辑通过jQuery通过iframe加载的DOM元素.真的吗?如果是这样,如何编辑通过iframe加载的元素的CSS?
This makes me think that I can't edit DOM elements loaded via iframe with jQuery. Is that true? If so, how do I edit CSS of elements that are loaded via iframe?
感谢Boda Cydo.
Thanks, Boda Cydo.
推荐答案
.contents()方法也可以是用于获取内容的文档iframe(如果iframe位于同一台上)域作为主页.
The .contents() method can also be used to get the content document of an iframe, if the iframe is on the same domain as the main page.
来自: http://api.jquery.com/contents/
这篇关于是否可以编辑通过< iframe>加载的DOM元素.用jQuery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!