【问题标题】:Label not displaying in JQuery remote success callback标签未显示在 JQuery 远程成功回调中
【发布时间】:2016-03-09 22:14:58
【问题描述】:

我想在远程 JQuery 验证成功回调完成后显示一个标签。但它似乎没有执行代码。

这是我的代码。

$('#Location').rules("add", {
  required: true,
  //minlength: 5,
  maxlength: 5,
  messages: {
    required: "Required input",
    minlength: jQuery.validator.format("Please, {0} characters are necessary"),
    maxlength: jQuery.validator.format("Please, {0} characters are necessary"),
    remote: jQuery.validator.format("Could not locate zip code")
  },
  remote: {
    url: "CheckLocation",
    type: "post",
    data: {
      Location: function() {
        return $('#Location').val();
      },
      success: function(data) {
        //console.log(data);
        $('#locationSuccess').attr('display', ''); // not working
      }
    }
  }
});
<label id="locationSuccess" style="color: green; display: none">ahh, Somewhere</label>

【问题讨论】:

  • 使用$('#locationSuccess').show();
  • 它不起作用,因为display 不是attribute;这是一个 CSS 属性。试试.css() 而不是.attr()
  • 再次声明,请不要将代码片段功能用于任何不会在此页面中运行的代码。已移除。谢谢。

标签: jquery html css jquery-validate


【解决方案1】:

使用 jQuery .show() 方法

$('#locationSuccess').show();

或 .css()

$('#locationSuccess').css('display', '');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-20
    • 2015-06-06
    • 2012-05-04
    • 1970-01-01
    • 2021-12-27
    • 2018-12-23
    相关资源
    最近更新 更多