0

如何仅在 focusout 事件中将验证添加到文本框控件?

有人有想法吗?

4

2 回答 2

0

你的html是:

<input type="text">

还有你的 jQuery:

$('input').blur(function(){
    var text = $(this).val();
   //do smth with your text...
});
于 2016-09-01T12:52:28.233 回答
0

$("#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;
    }    

})
于 2016-09-01T12:48:33.550 回答