我有这个代码:
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");
}
最佳答案
使用 is
测试 :invalid
伪类的函数:
if ($(this).is(":invalid")) {
showMessage("Invalid value");
}
关于javascript - Jquery,如何知道输入何时有 :invalid selector?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14384593/