在 HTML 中点击元素时执行脚本?
htmlweb developmentfront end technology更新于 2025/8/18 1:48:17
使用 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>
相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

