【问题标题】:Unable to set the custom css class for error message无法为错误消息设置自定义 css 类
【发布时间】:2014-09-04 16:36:43
【问题描述】:

我正在尝试将自定义 CSS 类添加到错误消息中。我想让错误消息变为红色,并将验证失败的输入元素突出显示为红色。

代码示例:Fiddle

我已将初始化设置为:

 ko.validation.init({
        grouping: { deep: true, observable: false },
        decorateElement: true,
        insertMessages: true,
        decorateElementOnModified: true,
        decorateInputElement: true,
        errorClass:'error',
        errorMessageClass :'error',
        errorElementClass:'error'
    });

但我还是看不到 css 的变化

【问题讨论】:

    标签: knockout.js knockout-validation


    【解决方案1】:

    永远不会调用您的 init 来初始化验证 -

    http://jsfiddle.net/W3pQt/6/

    这样称呼——

    init();
    

    【讨论】:

      【解决方案2】:

      问题是你的initKoValidation() 函数永远不会被调用,那是因为你的vm.init() 永远不会被调用。试试这个:

      function vm(){
          var init = function () {
              initKoValidation();
          }
      
          var self = this;
          self.user = ko.observable(new User());
      
          init(); // <--- the missing piece
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-08-23
        相关资源
        最近更新 更多