我在 iFrame 中使用 jQuery 时遇到问题。
这是我的测试设置:
index.html:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#A").contents().find('#B').addClass('Z');
});
</script>
</head>
<body>
<iframe id="A" src="test.html" style="width:700px; height: 1000px;" frameborder="0"></iframe>
</body>
</html>
测试.html:
<html>
<head>
<title>test</title>
</head>
<body>
<div id="B">testcontent</div>
</body>
</html>
正常情况下,当页面加载时,在源代码中,“Z”应该被添加为一个类,但事实并非如此。有谁知道问题可能是什么?这两个文件都在同一个(本地)文件夹中。
最佳答案
试试这个
$("iframe").load(function(e){
$(this).contents().find('#B').addClass('Z');
});
关于javascript - 在 iFrame 中使用 jQuery 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18536947/