判斷是否觸發回車鍵和判斷某個input是否聚焦


//點擊回車鍵時,判斷姓名input框是否獲得焦點,若聚焦,return。
$(window).keydown( function(e) {
var key = window.event?e.keyCode:e.which;
if(key == 13){
        var myInput = document.getElementById('name');  //獲取到ID為name的input
if (myInput == document.activeElement) {
// console.log('獲取焦點');
return false;
}
}
});


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM