如何仅在 focusout 事件中将验证添加到文本框控件?
有人有想法吗?
你的html是:
<input type="text">
还有你的 jQuery:
$('input').blur(function(){
var text = $(this).val();
//do smth with your text...
});
$("#txt1").blur(function(){
var v = $("#txt1").val();
if(v == "test"){
alert('valid');
}
else{
alert('invalid');
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
T1: <input type="text" id="txt1">
T2: <input type="text" id="txt2">
参考:https ://api.jquery.com/focusout/
.focusout(function() {
// Put your validation code here
if(!valid){
return false;
}
})
或者
.blur(function() {
// Put your validation code here
if(!valid){
return false;
}
})