本文操作环境:windows7系统、javascript1.8.5版、DELL G3电脑
javascript怎么设置元素点击事件?
很简单,看下面的代码:
复制代码1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
window.onload=function(){
var btn = document.getElementById("btn");
btn.onclick=function(){
alert("这就是点击事件~");
}
}
</script>
</head>
<body>
<button id="btn">点击一下吧</button>
</body>
</html>
登录后复制
推荐学习:《javascript基础教程》
以上就是javascript怎么设置元素点击事件的详细内容,更多请关注靠谱客其它相关文章!
最后
以上就是刻苦小丸子最近收集整理的关于javascript怎么设置元素点击事件的全部内容,更多相关javascript怎么设置元素点击事件内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复