我有这个代码:
HTML
<input type="text" data-value="1" data-type="input-records" placeholder="Value" pattern="\d{1,4}$" />
CSS
input[type=text]:invalid { background-color: red; }
JavaScript
$("[data-type=input-records]").die().live("keypress", function (e) {
if (!($(this).val().length + 1) < 5) {
e.preventDefault();
return;
}
// More code below...
});
我想做这样的验证:
if (!$(this).hasSelector(":invalid")) {
showMessage("Invalid value");
}
Use the is函数来测试:invalid
伪类:
if ($(this).is(":invalid")) {
showMessage("Invalid value");
}
Example: http://jsbin.com/ikuwur/2/edit
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)