0

如何在jquery中进行验证时更改div的高度

此 div 包含错误消息。每当消息更新时,div 应该更新它的高度

  errorPlacement : function(error, element) {

        $('#error_container').show();
        error.appendTo($('#error_container'));
        $('#error_container').append("<br>");
    },

我试图申请

     $("#error_container").attr({ 
          height: "auto"
        });

但没有找到合适的地方

4

3 回答 3

1

像这样设置

$("#error_container").css('height', 'auto');
于 2012-09-03T06:20:01.903 回答
1

试试这样:

$("#error_container").attr("style","height:auto");

或者.css()像这样使用;

$("#error_container").css('height', 'auto');
于 2012-09-03T06:22:22.853 回答
0

试试这个。我还更改了您
对底部填充的添加,因此您可以轻松删除它。

errorPlacement : function(error, element) {
  $('#error_container').show();
  error.appendTo($('#error_container'));
  $('#error_container').css('padding-bottom', '20px');
  $("#error_container").css('height', 'auto');
},

如果您需要撤消填充,您可以执行以下操作:

  $('#error_container').css('padding-bottom', '0');
于 2012-09-03T06:20:48.657 回答