【问题标题】:How to change the height of div while a validate in jquery如何在jquery中进行验证时更改div的高度
【发布时间】:2012-09-03 06:18:06
【问题描述】:

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

此 div 包含错误消息。 div 应该随时更新它的高度 消息已更新

  errorPlacement : function(error, element) {

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

我尝试过申请

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

但没有找到合适的地方

【问题讨论】:

    标签: jquery jquery-ui jquery-validate


    【解决方案1】:

    这样设置

    $("#error_container").css('height', 'auto');
    

    【讨论】:

    • 在 validate 方法中放在哪里。
    • 但是当它不在errorPlacement中时:function(error, element) {它应该是更新的。
    • 你可以在jquery调用上面试试
    【解决方案2】:

    试试这样:

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

    或者像这样使用.css()

    $("#error_container").css('height', 'auto');
    

    【讨论】:

      【解决方案3】:

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

      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');
      

      【讨论】:

      • 在 validate 方法中放在哪里
      • 我建议使用填充而不是
        标签 - 我再次编辑了我的答案。如果这对您不起作用,请告诉我。
      • 如果我想使用 -> 带有错误消息的符号,我该如何删除它。我们成功了:function(label){} 方法来处理这个
      猜你喜欢
      • 1970-01-01
      • 2013-09-11
      • 1970-01-01
      • 2015-03-21
      • 2014-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-06
      相关资源
      最近更新 更多