Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/474.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在iframe内部单击按钮时,如何增加iframe的高度?_Javascript_Jquery_Html_Wordpress_Iframe - Fatal编程技术网

Javascript 在iframe内部单击按钮时,如何增加iframe的高度?

Javascript 在iframe内部单击按钮时,如何增加iframe的高度?,javascript,jquery,html,wordpress,iframe,Javascript,Jquery,Html,Wordpress,Iframe,所以,我一直在一个wordpress网站上工作,该网站的网页中有一个iframe。iframe包含两个按钮,使用jquery append将内容包含在iframe中。目前,我包含了一个javascript函数,可以在每次加载iframe时更改高度。但我想在按下iframe内的按钮时更改高度。 iframe在wordpress的插件文件中定义,iframe src在wordpress主题文件夹中定义为模板。 包含iframe标记的插件文件 <iframe src="http://localh

所以,我一直在一个wordpress网站上工作,该网站的网页中有一个iframe。iframe包含两个按钮,使用jquery append将内容包含在iframe中。目前,我包含了一个javascript函数,可以在每次加载iframe时更改高度。但我想在按下iframe内的按钮时更改高度。 iframe在wordpress的插件文件中定义,iframe src在wordpress主题文件夹中定义为模板。 包含iframe标记的插件文件

<iframe src="http://localhost/mysite/firstrate/" frameborder="0" 
scrolling="no" onload="resizeIframe();" id="starwindow" ></iframe>
<script>
var obj=document.getElementById("starwindow");
function resizeIframe() {
obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
}
</script>   
包含iframe模板文件的主题文件

<button class="add_form_field" ><span>ADD</span></button>
<button id="button" class="submit_button"> SUBMIT </button>
<input type="radio" class="rating1" id="1star5" name="rating1" value="5" />
<label for="1star5" title="Five Stars">5 stars</label>
<input type="radio" class="rating1" id="1star4" name="rating1" value="4" />
<label for="1star4" title="Four Stars">4 stars</label>
<input type="radio" class="rating1" id="1star3" name="rating1" value="3" />
<label for="1star3" title="Three Stars">3 stars</label>
<input type="radio" class="rating1" id="1star2" name="rating1" value="2" />
<label for="1star2" title="Two Stars">2 stars</label>
<input type="radio" class="rating1" id="1star1" name="rating1" value="1" />
<label for="1star1" title="One Star">1 star</label>
我希望iframe在按下iframe内部的按钮时增加高度,以便在按下按钮时不会出现滚动条。
提前感谢您。

您可以使用jQuery:

$('#starwindow').load(function(){

        var iframe = $('#starwindow').contents();

        iframe.find("#button").click(function(){
               resizeIframe();
        });
});
按要用于iframe调整大小的元素更改“按钮”

编辑:

并将功能更改为添加/删除高度

resizeIframe(mode) {
    if(mode=='add') {
        //code to add height
    }
    else {
        //code to delete height
    }
}

我还遇到了一些其他问题。当我按下add按钮时,另一个名为delete的按钮被创建。如何将该按钮也包含在代码中,从而降低iframe高度。我想,我没有向您说明这个问题。在第一次调用“添加”按钮后,iframe中的内容会发生更改。创建了一个新的“删除”按钮。我现在在问题中包含了该按钮的屏幕截图。因此,iframe.finddelete.clickfunction{}将不起作用,因为删除按钮不在var-iframe=$'starwindow'中。contents。如何在调用Add按钮后包括删除按钮?@codewiz我知道了,那么您必须运行var-iframe=$'starwindow'。contents;再次包括删除按钮。谢谢你的帮助。
resizeIframe(mode) {
    if(mode=='add') {
        //code to add height
    }
    else {
        //code to delete height
    }
}