使用JavaScript
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>Title</title>
<script type="text/javascript">
window.onload = function(){
var btObj = document.getElementById("bt");
btObj.onclick = function(){
alert("执行onclick事件");
}
}
</script>
</head>
<body>
<button id="bt">按钮</button>
</body>
</html>
使用jQuery
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>Title</title>
<script type="text/javascript" src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script> <!--引入jquery -->
<script type="text/javascript">
$(function(){
var $btObj = $("#bt"); //按id查询标签对象
$btObj.click(function(){
alert("jquery的单击事件");
});
});
</script>
</head>
<body>
<button id="bt">按钮</button>
</body>
</html>