
使用 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>

