1
我已經創建了一個輸入框,通過使用tab鍵進行驗證,但是需要在按下回車鍵後進行驗證。如何通過輸入密鑰驗證答案?
這裏,刻度顯示符號後,才輸入正確的答案,然後按Tab鍵。然後它轉到下一個輸入框,並進行驗證。
但是,當我輸入正確的答案並敲入輸入框本身內部的輸入時,驗證需要發生。
對於我試過這個JS代碼:
$(document).keypress(function(e) {
if(e.which == 13) {
checktxt(h,v,w,c)
}
});
function checktxt(h,v,w,c) {
var th=$("#"+h).val();
var tv=$("#"+v).val();
if(th.toLowerCase()==tv.toLowerCase()) {
$("."+c).show();
$("."+w).hide();
} else if(tv.toLowerCase()=="") {
} else {
$("."+c).hide();
$("."+w).show();
}
}
而且,當我按下回車鍵沒有得到驗證。
而我的HTML代碼
<div>
<input id="texthidden1" type="hidden" value="877" />
<input id="textvisible1" type="text" value="" onblur="javascript:checktxt('texthidden1','textvisible1','wrong1','correct1');" />
<div class="wrong1"><img src="../images/smallwrong.png"/></div>
<div class="correct1"><img src="../images/smallgreen.png"/></div>
</div>
我還需要消失蜱圖像當我刪除輸入框中的內容。
非常感謝。它的工作的罰款。 – Anitha
當我刪除輸入框的內容時,我還需要勾選圖像消失。 – Anitha
@Anitha你可以在輸入上綁定一個更改事件偵聽器,並檢查該值是否爲空。 – Deep