laoguiaabb
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="div1">HELLO DIV
<p>hello p</p>
</div>
<script>
var ele=document.getElementById("div1"); //通过事件的对象去绑定函数
ele.onclick=function () {
alert("111")
}
</script>
</body>
</html>

=================== 注:还有一种就是直接在标签内加 onclick 的函数名,在js代码里写function ===================

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2017-11-29
  • 2022-02-09
  • 2021-12-25
  • 2022-12-23
  • 2022-12-23
  • 2022-02-09
猜你喜欢
  • 2022-02-09
  • 2021-09-19
  • 2022-01-14
  • 2021-11-12
  • 2022-12-23
  • 2020-03-28
  • 2021-05-20
相关资源
相似解决方案