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值 


轉載請註明:前端錄»js 設置焦點 判斷控件是否得到焦點 判斷哪一個控件得到焦點javascript

相關文章
相關標籤/搜索