现在我正在做一个简单的HTML/jQuery脚本,当我点击一个由iframe it本身加载的按钮时,我想要改变iframe的高度。
看看我的代码:
index.php:
<div id="outerdiv">
<iframe src="http://beta.sportsdirect.bg/test/iframe.php" id="inneriframe" scrolling="no" target="_parent"></iframe>
</div>iframe.php:
<HTML>
<head>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
</head>
<script type="text/javascript">
$("#SuperWebF1").click(function(){
$('#inneriframe, #outerdiv', window.parent.document).css({"height":"450px"});
})
</script>
<div style="display:block;height:300px;">
<h3>The iframe content</h3>
<button type="button" id="SuperWebF1">Click me to resize the holding Iframe!</button>
</div> 这是一个index.php的演示:http://beta.sportsdirect.bg/test/
当您打开它时,您将看到由iframe加载的按钮。当你点击按钮时,iframe不会改变高度!
怎么了,有什么问题吗?
你能帮我把这玩意修好吗?
提前感谢!
发布于 2014-11-01 04:18:57
以下是我对您的代码所做的一些更改。
//function call needed to make sure page is loaded before javascript runs
$(document).ready(function(){//begin document ready function
//on click event
$(document).on("click","#SuperWebF1",function(){//begin on click event
//change the height of selected elements
$('#inneriframe, #outerdiv', window.parent.document).css({"height":"450px"});
});//end on click event
});//end document ready functionhttps://stackoverflow.com/questions/26682579
复制相似问题