我希望我的输入validationMessages以红色显示所有页面。 我怎么能这样做才能在全球范围内发挥作用?
knockout.validation.debug.js有这段代码
var defaults = {
registerExtenders: true,
messagesOnModified: true,
errorsAsTitle: true, // enables/disables showing of errors as title attribute of the target element.
errorsAsTitleOnModified: false, // shows the error when hovering the input field (decorateElement must be true)
messageTemplate: null,
insertMessages: true, // automatically inserts validation messages as <span></span>
parseInputAttributes: false, // parses the HTML5 validation attribute from a form element and adds that to the object
writeInputAttributes: false, // adds HTML5 input validation attributes to form elements that ko observable's are bound to
decorateInputElement: false, // false to keep backward compatibility
decorateElementOnModified: true,// true to keep backward compatibility
errorClass: null, // single class for error message and element
errorElementClass: 'validationElement', // class to decorate error element
errorMessageClass: 'validationMessage', // class to decorate error message
allowHtmlMessages: false, // allows HTML in validation messages
grouping: {
deep: false, //by default grouping is shallow
observable: true, //and using observables
live: false //react to changes to observableArrays if observable === true
},
validate: {
// throttle: 10
}
};
答案 0 :(得分:2)
插入的错误消息默认为validationMessage
指定了类。如果要全局更改样式,只需为该类设置一些css规则即可。
.validationMessage
{
color: red;
}
当然,您也可以选择覆盖默认的邮件类。
ko.validation.init({
errorMessageClass: 'my-error-class'
});