Jquery,如何知道输入何时有:无效选择器?

2023-11-25

我有这个代码:

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(使用前将#替换为@)

Jquery,如何知道输入何时有:无效选择器? 的相关文章

随机推荐