代码示例:(标识:eg_js_events_onclick_2)
<!DOCTYPE html>
<html>
<head>
<script>
function myFunction() {
  document.getElementById("demo").innerHTML = "Hello World";
}
</script>
</head>
<body>

<p>单击按钮以触发函数。</p>

<button onclick="myFunction()">点击这里</button>

<p id="demo"></p>

</body>
</html>
运行结果: