Html <button onclick = " ">是一个事件属性,当按钮被单击时执行一个脚本。这个属性是所有浏览器支持。它还可以用于当单击按钮时调用一个函数。
句法:
<button onclick="单击脚本">
示例 1:以下示例描述了如何使用按钮标签:
<!DOCTYPE HTML>
<html>
<head>
<title>
点击按钮的例子
</title>
<script>
function welcome() {
window.open("https://www.rocschool.com/");
}
</script>
</head>
<body style = "text-align:center">
<button onclick="welcome()"> 欢迎访问我们的网站 </button>
</body>
</html>输出:

| 元素 | Chrome | IE | Firefox | Safari | Opera |
|---|---|---|---|---|---|
| <onClick> | Yes | Yes | Yes | Yes | Yes |
