我在IE11和Jquery Validator中遇到了一个有趣的问题。它始于在输入type =“ email”和输入type =“ password”上发生的相同问题-似乎任何输入BESIDES文本都会显示默认错误消息Please enter a value that is greater or equal to undefined
。
因此,首先将输入类型从电子邮件更改为文本,但是我无法将密码类型更改为文本-我不想显示密码...
我不知道为什么会这样,或者不确定的变量是从哪里来的,甚至是如何找出来的。有什么建议?
下面的代码:
$.validator.addMethod("valid_pass", function(value, element, regexpr) {
return this.optional(element) || regexpr.test(value);
}, "Your password must be between 8-15 characters and contain at least 1 number.");
$("#element1").validate({
errorPlacement: function(label, element) {
label.appendTo(element.parent('td').siblings('td'));
},
rules: {
password: { required: true, valid_pass: /^(?=.*\d).{8,15}$/ },
password2: { required: true, equalTo: "#password" }
},
messages: {
password: { required: "Create a password." },
password2: {
required: "Re-enter your password.",
equalTo: "Your passwords do not match."
}
}
});
和
<tr>
<td class="align-right"> Password: <a class="tooltip ml5" title="Password must be between 8-15 characters & include at least 1 number">(?)</a></td>
<td><input type="password" id="password" name="password" maxlength="15" tabindex="9"/></td>
</tr>
<tr>
<td class="align-right"> Confirm password: </td>
<td><input type="password" name="password2" maxlength="15" tabindex="10"/>
</td>
</tr>
错误地,我找到了一种解决该症状的解决方案,但不是解决此问题的源头...
似乎“ min”,“ max”和“ step”已添加到输入-通过验证器本身(?)或通过浏览器(似乎IE11做到了这一点,以及Mac上的safari 7.0.1) 。不仅是密码输入-它在电子邮件输入,常规的旧文本输入以及复选框中进行了输入。为什么?只有浏览器之神知道。为了解决这个问题,我使用了Jquery,并运行以下代码来删除min,max和step:
$('input, radio, textarea,select, checkbox').each(function() {
$(this).removeAttr('min max step');
});
作为最后一个脚本,我在$ {document).ready中运行
在不删除它们的情况下,由于min,max和step是范围输入的属性,因此验证程序认为这是范围输入,并尝试将其计算为数字...
删除这些属性即可解决此问题,而该问题已通过魔术解决。很奇怪,但是行得通..
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句