<input type="text" class="input-xlarge required" id="newName" maxlength='50'>
<input type="text" class="input-xlarge required emails" id="newAddress" maxlength='500'>
利用JQuery对上述两个输入框进行验证,你是否能看出上述代码的缺陷。
问题描述:第一个输入框验证正常,但第二个输入框验证无效,也不是完全无效,当你激活第二个输入框再失去焦点时,也有验证提示信息显示。
对于JQuery的验证,用得不多,这次碰到的异常让我很是困惑,费了不少时间,但总算是耐着性子解决了。
解决方案:
<input type="text" class="input-xlarge required" name="newName" id="newName" maxlength='50'>
<input type="text" class="input-xlarge required emails" name="newAddress" id="newAddress" maxlength='500'>
加上name后,JQuery验证恢复正常。
总结:
利用JQuery框架进行验证时,输入框必须加上name属性,否则就会出现如上异常。这种异常排查起来还是挺麻烦。吃一堑长一智,遇到问题是好事。