當元素被 HTML 中單擊時執行指令碼?
使用 onclick 屬性來執行指令碼,當元素在 HTML 中被點選時。
示例
您可以嘗試執行以下程式碼來實現 onclick 屬性 −
<!DOCTYPE html>
<html>
<body>
<button onclick = "display()">Click</button>
<p id = "test"></p>
<script>
function display() {
document.getElementById("test").innerHTML = "You clicked the button!";
}
</script>
</body>
</html>
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP