admin管理员组文章数量:1026989
I have this code:
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...
});
I want to make a validation like this:
if (!$(this).hasSelector(":invalid")) {
showMessage("Invalid value");
}
I have this code:
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...
});
I want to make a validation like this:
if (!$(this).hasSelector(":invalid")) {
showMessage("Invalid value");
}
Share
Improve this question
asked Jan 17, 2013 at 17:22
Sergio FloresSergio Flores
5,4275 gold badges38 silver badges60 bronze badges
1 Answer
Reset to default 28Use the is
function to test for the :invalid
pseudoclass:
if ($(this).is(":invalid")) {
showMessage("Invalid value");
}
Example: http://jsbin.com/ikuwur/2/edit
I have this code:
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...
});
I want to make a validation like this:
if (!$(this).hasSelector(":invalid")) {
showMessage("Invalid value");
}
I have this code:
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...
});
I want to make a validation like this:
if (!$(this).hasSelector(":invalid")) {
showMessage("Invalid value");
}
Share
Improve this question
asked Jan 17, 2013 at 17:22
Sergio FloresSergio Flores
5,4275 gold badges38 silver badges60 bronze badges
1 Answer
Reset to default 28Use the is
function to test for the :invalid
pseudoclass:
if ($(this).is(":invalid")) {
showMessage("Invalid value");
}
Example: http://jsbin.com/ikuwur/2/edit
本文标签: JavaScriptJQueryhow to know when input have a invalid selectorStack Overflow
版权声明:本文标题:javascript - Jquery, how to know when input have a :invalid selector? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1738363478a1567627.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论