1.基本的JavaScript页面:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<!-- JavaScript代码,需要写在script标签中 -->
<script type="text/javascript">
//当整个文档都加载完成之后再执行函数中的内容
window.onload=function(){
//1.获取按钮对象
var btnEle = document.getElementById("btnId");
//2.给对象绑定单击事件
btnEle.onclick=function(){
alert("你好 蔡徐坤");
};
};
</script>
</head>
<body>
<button id="btnId">点击这个按钮</button>
</body>
</html>
2.基本的jQuery页面:需要添加js文件才能使用
jQuery 文件jquery-1.7.2.js下载地址:https://download.csdn.net/download/weixin_40370904/12692261
(1)添加js文件
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<!-- 引入Jquery的js文库 -->
<script type="text/javascript" src="script/jquery-1.7.2.js"></script>
<script type="text/javascript">
//相当于window.onload = function(){};
$(function(){
//获取按钮对象并且给他绑定单击事件
$("#btnId").click(function(){
//弹出提示框
alert("蔡徐坤很帅!");
});
});
</script>
</head>
<body>
<button id="btnId">点击这个按钮</button>
</body>
</html>