js 設置焦點 判斷控件是否獲得焦點 判斷哪個控件獲得焦點


設置焦點

 

<html>    

<head>    

<title>設置焦點</title>    

<mce:script language ="javascript"><!--
    

function init(){    

var ctrl=document.getElementById("UserName");    

ctrl.focus();    

}   
// --></mce:script>    

</head>    

  

<body onload="init()" >    

<h1>設置焦點</h1>    

姓名:<input type="text" id="UserName">    

</body>    

</html>  

判斷控件是否獲得焦點

if(document.activeElement.id="txtIdHouse")
{
}

判斷哪個控件獲得焦點

 

var act = document.activeElement.id;
act就是現在獲得焦點控件的id值

 

 

 

 

 


免責聲明!

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



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