[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
- 首頁
- JAVA 目錄
- JAVA WEB 目錄
- JAVA 其他未分類 目錄
- Grails目錄
- jQuery 目錄
- Apache 目錄
- JavaScript 目錄
- Spring + Hibernate 目錄
- Hibernate 目錄
- Linux 目錄
- 程式開發工具目錄
- MySQL 目錄
- PHP目錄
- C/C++ 目錄
- Google App Engine 目錄
- HTML5/CSS3
- 程式開發基本資訊
- Android
- Oracle 目錄
- Struts 目錄