HTML部分
<body>
<button id="btn">单击我</button>
<button id="delAll">删除所有事件</button>
<div id="test"></div>
</bady>
jQuery代码
<script type="text/JavaScript" src="./js/jquery-3.4.1.js"></script>
<script type="text/JavaScript">
$(document).ready(function(){
$('#btn').bind("click",function(){
$('#test').append("<p>我的绑定函数1</p>");
}).bind("click",function(){
$('#test').append("<p>我的绑定函数2</p>");
}).bind("click",function(){
$('#test').append("<p>我的绑定函数3</p>");
});
//事件解绑
$('#delAll').click(function(){
$('#btn').unbind("click");
});
});
</script>
Java script 代码
<script type="text/JavaScript">
window.onload=function(){
let but=document.getElementById('btn');
console.log(but);
let text=document.getElementById('test');
console.log(text);
let del=document.getElementById('delAll');
console.log(del);
but.onclick=function(){
text.innerHTML+=`<p>我的绑定函数1</p>
<p>我的绑定函数2</p>
<p>我的绑定函数3</p>`;
};
del.onclick=function(){
but.onclick=null;
};
}
</script>