2016-09-01 50 views

回答

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; 
    }  
}) 

OR

.blur(function() { 

    // Put your validation code here 
    if(!valid){ 
     return false; 
    }  

}) 
+0

如果以这种方式尝试,验证发生在keyup事件上也 –

+0

请尝试代码片段。这是你想要或没有? –

0

你的HTML是:

<input type="text"> 

和你的jQuery:

$('input').blur(function(){ 
    var text = $(this).val(); 
    //do smth with your text... 
});