在 HTML 中當元素被點選時執行指令碼?
在 HTML 中,使用 onclick 屬性可在單擊元素時執行指令碼。
示例
嘗試執行以下程式碼來實現 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