当元素被 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