我已经在HTML页面中嵌入了使用jQuery移动页面的功能,但是当我尝试使用jQuery访问其内部div标签时,find方法不会返回任何内容。

带有jQuery的HTML

<iframe id="myframe" src="../codiqa/mobile.htm"
    style="width: 500px; height: 520px;
    border: 1px solid #ccc; margin-top:20px;">
</iframe>


这里

$("#myframe").load(function(){
    alert($(this).contents().find('#mobilebutton').html());
});


iframe中的移动代码

<div id="mobilebutton" data-role="button">Mobile Button</div>

最佳答案

使用window.load代替$("#myframe").load。框架的元素将在$(window).load事件中准备就绪,您将可以访问它们。

$(window).load(function(){
    alert($("#myframe").contents().find('#mobilebutton').html());
});

关于javascript - jQuery无法在iframe中查找.find()元素,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14684797/

10-11 22:21
查看更多