當元素獲得焦點時,在 HTML 中執行指令碼?
使用 onfocus 屬性,在元素獲得焦點時,在 HTML 中執行指令碼。
示例
你可以嘗試執行以下程式碼來實現 onfocus 屬性 −
<!DOCTYPE html>
<html>
<body>
<p>Enter subject name below,</p>
Subject: <input type = "text" id = "sname" onfocus = "display(this.id)">
<br>
<script>
function display(val) {
document.getElementById(val).style.background = "blue";
}
</script>
</body>
</html>
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP