Iframe高度调整不工作

iframe height adjust not working

本文关键字:工作 调整 高度 Iframe      更新时间:2023-09-26

我有一个iframe与一个按钮,当点击展开列表。我希望该iframe的高度调整,一旦按钮被点击。下面是我在iframe中的代码:

     <script>
$(function() {
    $("#field12593102_1").click(function() {
        window.parent.adjustIFrameHeight();
    });
});
</script>

父框架中的代码如下:

    function adjustIFrameHeight(){
$('.childframe').css('height', function(index) {
  return index +=400;});
};

我知道父框架代码可以工作,因为我已经尝试过它而不调用函数,但它不像现在这样工作。

您需要使用css()调用的函数的第二个参数

function adjustIFrameHeight(){
$('.childframe').css('height', function(index,value) {
  return value + 400;});
};

第一个参数是当前元素在jQuery-object中的索引,而不是当前属性(在本例中是宽度)。

你也可以使用:

function adjustIFrameHeight(){
    $('.childframe').css('height', '+=400');
    };

change:

function adjustIFrameHeight(){
$('.childframe').css('height', function(index) {
  return index +=400;});
};

:

function adjustIFrameHeight(){
    $('.childframe').css({height: function(index, value) {
      return value +=400;}
    });
};