Jquery,如何知道输入框是否有 :invalid 选择器?

15

我有这段代码:

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");
}
1个回答

28

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接