我想使用在iframe中单击的按钮执行一些jquery脚本,并且输出在iframe....Is之外?我的主html如下所示:
<html>
<head></head>
<body>
<div id="test" >test</div>
<iframe width="100px" height="100px" src="test.php" ></iframe>
</body>
</html>对于test.php:
<html>
<head>
<script src="jquery.min.js" ></script>
<script>
$(document).ready(function(){
$('#btn').click(function(){
$('#test').hide(); // i want to hide this whenever a button with id btn inside and iframe is triggered
});
});
</script>
</head>
<body>
<button id='btn' >click</button>
</body>
</html>我就是这样做的,但这不管用。谢谢你的想法..。:)
发布于 2014-01-13 07:31:22
你可以用这个:-
$('#test', window.parent.document).hide();发布于 2014-01-13 07:31:16
$(document).ready(function(){
$('#btn').click(function(){
$(window.parent.getElementById('test')).hide();
});
});发布于 2014-01-13 07:53:24
如果您的iframe和当前页面的域相同,则可以使用window.parent,否则它将无法工作。
https://stackoverflow.com/questions/21085964
复制相似问题