填写输入后,该插件会插入一个标签,但是我希望在页面加载时插入所有标签。任何想法都会很棒,谢谢。
该插件的链接在这里。
http://jqueryvalidation.org/documentation/ http://jqueryvalidation.org/documentation/
我想有一种方法可以用来插入所有标签。
代码示例如下。
在加载页面上,字段可能如下所示...
<div id="name-field" class="field input-text">
<input type="text" id="name" name="name" onblur="if (this.value=='') this.value = 'Name'" onfocus="if (this.value=='Name') this.value = ''" value="Name" class="requiredAstrix" />
<div id="name-error-label" class="error-label f3a cf98">
This field is required
<div class="arrow s14"></div>
</div>
<div id="name-hover-label" class="hover-label cf2"></div>
</div>
Onblur 插件按如下方式插入标签...(这就是我希望所有字段在页面加载时的方式)
<div id="name-field" class="field input-text">
<input type="text" id="name" name="name" onblur="if (this.value=='') this.value = 'Name'" onfocus="if (this.value=='Name') this.value = ''" value="Name" class="requiredAstrix" />
<label for="name" class="error checked"> </label>
<div id="name-error-label" class="error-label f3a cf98">
This field is required
<div class="arrow s14"></div>
</div>
<div id="name-hover-label" class="hover-label cf2"></div>
</div>
只需使用the .valid() method http://jqueryvalidation.org/valid/以编程方式在 DOM 上执行验证测试。
$(document).ready(function() {
$('name-field').validate({ // initialize the plugin on your form
// rules,
// messages,
// options,
// callback functions
});
$('name-field').valid(); // immediately fire validation on DOM ready
});
工作演示: http://jsfiddle.net/JVzKd/ http://jsfiddle.net/JVzKd/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)