2016-09-01 51 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... 
});