一旦div达到一定高度,使用jQuery将div的高度更改为auto [英] Change a div's height to auto using jQuery once the div reaches a certain height

查看:192
本文介绍了一旦div达到一定高度,使用jQuery将div的高度更改为auto的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个div,允许用户动态添加其他表单输入。我希望能够在达到一定高度后将div的高度更改为auto。这是我的jQuery代码,虽然它目前似乎没有工作。

I have a div that lets the user add additional form inputs dynamically. I'd like to be able to change this div's height to auto once it reaches a certain height. Here is the jQuery code I have, though it doesn't seem to be working at the moment.

$(document).ready(function(){
if($('#upload3').height() > 400){ $('#upload3').css('width','auto'); }  });


推荐答案

这只会在文档准备就绪时运行ONCE。你需要把它放在 resize()事件处理程序中:

This will only run ONCE when the document is ready. You need to put it inside a resize() event handler:

$('#upload3').resize(function() {
  if($(this).height() > 400){ $(this).css('height','auto'); }  });
});

这篇关于一旦div达到一定高度,使用jQuery将div的高度更改为auto的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆