在 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