在iFrame中使用jQuery不起作用
Using jQuery inside iFrame not working
我在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>
test.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');
});
您必须在具有HTTP方案(http://
或https://
)的Web服务器上运行它。
在某些浏览器中,使用文件方案(file://
)可以防止这种跨帧访问。
相关文章:
- 自动完成 jquery 不起作用
- 悬停时的Jquery不起作用
- 使用DateTimePicker插件的JQuery不起作用
- 无限滚动jquery不起作用
- 角度2触发器'单击'使用jquery不起作用
- 在 jQuery 不起作用的情况下迭代变量
- 切换下 jquery 不起作用
- 简单的jquery不起作用,并返回错误
- 等效于getElementbyName的jQuery不起作用
- Jquery不起作用,但我想一切都好
- 当按钮从ajax调用时,jquery不起作用
- 在jQuery不起作用的情况下阻止表单提交
- 为什么这个jquery不起作用
- 带有变量选择器的 Jquery 不起作用
- 简单的JavaScript/jQuery不起作用
- Wordpress jquery不起作用(计算系统)
- Django 模板内联 jQuery 不起作用
- 提示计算器 jquery 不起作用
- 追加 jquery 不起作用
- 正则表达式 jQuery 不起作用