我使用的是敲除验证插件,它运行良好,但我有一个小问题,我想通过使用css使验证跨度稍微突出一点,我只想在输入元素之前插入验证跨度,现在它将在输入元素之后附加跨度。
,下面是它现在的渲染图
<input id="personName" class="form-control placeholder has-error" type="text" data-bind="value: name" placeholder="Your name" title="This field is required." data-orig-title="">
<span class="validationMessage" style="">This field is required.</span>
所以我只想把这个跨度附加在元素之前。
如果要自定义错误消息的显示方式,则需要使用预定义的验证绑定,在本例中为validationMessage
。
使用此绑定,您可以在任意位置显示给定属性的验证消息,例如在input
元素之前:
<span data-bind="validationMessage: name"></span>
<input id="personName" class="form-control placeholder has-error" type="text"
data-bind="value: name"
placeholder="Your name" title="This field is required." data-orig-title="">
此外,为了防止双重显示错误消息,您还需要关闭自动消息插入功能:
ko.validation.init({insertMessages: false});
演示JSFiddle。