[JavaScript HTML DOM]使用document物件,使用屬性document.activeElement

說明:
document.activeElement,取得現在動作的元件

此範例設計說明:
第一步、取得現在動作的元件的名稱
第二步、顯示元件的名稱在頁面上
程式:
<html>
<head>
<title>[JavaScript-HTML_DOM]使用document物件,使用屬性document.activeElement</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script>
function mytest() {
var returnData = "";
if (document.activeElement) {
                    var returnData = document.getElementById("returnData");
                    returnData.innerHTML = document.activeElement.tagName;
               }
}
</script>
</head>
<body onclick="mytest();">
[JavaScript-HTML_DOM]使用document物件,使用屬性document.activeElement
<br>
<img id="smiley1" border="0" src="smiley.gif" width="150" height="113">
<img id="smiley2" border="0" src="smiley.gif" width="152" height="128">
<button>按扭</button>
<input type="button" value="測試" />
<span id="returnData"></span>
</body>
</html>
圖:


按下按扭

 按下測試


相關範例:
待續

參考:
activeElement property (document)
Document.activeElement





 






 















其它文章

arrow
arrow

    PG Levin Li 發表在 痞客邦 留言(0) 人氣()