简体   繁体   English

iframe 高度调节不起作用

[英]iframe height adjust not working

I have an iframe with an button that when clicked expands a list.我有一个 iframe 带有一个按钮,单击该按钮会展开一个列表。 I want the height of that iframe to adjust once the button is clicked.单击按钮后,我希望 iframe 的高度进行调整。 Here is the code I have in the iframe:这是我在 iframe 中的代码:

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

The code in the parent frame is the following:父框架中的代码如下:

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

I know that the parent frame code works because I have tried it without a call to the function but it does not work as it is now.我知道父框架代码有效,因为我在没有调用 function 的情况下尝试了它,但它不像现在那样工作。

You need to use the 2nd argument of the function called by css()您需要使用由 css() 调用的 function 的第二个参数

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

The 1st argument is the index of the current element inside the jQuery-object, not the current property(width in this case).第一个参数是 jQuery 对象内当前元素的索引,而不是当前属性(在这种情况下为宽度)。

You may also use:您还可以使用:

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

change:改变:

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

to:至:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM