jquery 绑定事件:
// $(".btn").on(‘click‘,function () { // $(".c1").toggleClass(‘c2‘) // }); $(".btn").click(function () { $(".c1").toggleClass(‘c2‘) })
js 中的绑定事件
1、在标签中直接添加 onclick=fun() 事件, script中写函数
2、
<script defer> function clickHandler() { alert("onclick attribute in html"); } function clickHandler2(e) { alert(e.target.innerHTML); } document.getElementById("jsOnClick").onclick = clickHandler2; document.getElementById("addEventListener").addEventListener("click", clickHandler2); </script>
原文:https://www.cnblogs.com/yanxiaoge/p/10560768.html