简体   繁体   English

jQuery .height()不变

[英]jQuery .height() not changing

I have this code: 我有以下代码:

$(function() {
  $('#team-ch').click(function() {
    $('#team-camb-hert').height('auto');
  });
});

Which changes the height of a div on a link click. 这会更改链接点击时div的高度。 I have put an alert inside this function and can confirm it's being ran when the link it clicked, only the height of the target div isn't changing. 我在此函数中放了一个警报,可以单击链接时确认它正在运行,只是目标div的高度没有变化。 The target div has a height of 0 set in the CSS file to begin with but it's not being updated. 首先,目标div在CSS文件中设置的高度为0,但尚未更新。

Does anyone have any idea what may be going on here? 有谁知道这里可能会发生什么?

Try this: 尝试这个:

$(function() {
  $('#team-ch').click(function() {
    $('#team-camb-hert').css('height','auto');
  });
});

See how changing the height of an element works: 查看如何更改元素的高度:

  .test{ margin:10px; border-style:solid; border-width:1px; height:0px; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <input type="button" value="height:10px" onclick="$('.test').css('height','10px');"> <input type="button" value="height:auto" onclick="$('.test').css('height','auto');"> <input type="button" value="height:0px" onclick="$('.test').css('height','0px');"> <input type="button" value="hide" onclick="$('.test').hide();"> <input type="button" value="show" onclick="$('.test').show();"> <div class="test">test</br>test test</br>test</br>test</br></div> 

you can also try this: 您也可以尝试以下方法:

$(function() {
 $('#team-ch').click(function() {
 $('#team-camb-hert').attr('style','height:auto');
 });
});

Please put your script code below the jQuery library and run again as shown below, 请将您的脚本代码放在jQuery库下面,然后再次运行,如下所示,

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

$(function() { $('#team-ch').click(function() { $('#team-camb-hert').height('auto');});}); $(function(){$('#team-ch')。click(function(){$('#team-camb-hert')。height('auto');});});;

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

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