js:addEventListener与onclick同时使用
<button id="btn">点击</button><script>document.getElementById("btn").addEventListener('click', function (e) { console.log("点击了button1");})document.getElementById("btn").addEventListener('click', function (e) { console.log("点击了button2");})document.getElementById("btn").onclick = function (e) { console.log("点击了button3");}document.getElementById("btn").onclick = function (e) { console.log("点击了button4");}</script>
点击按钮后输出如下
点击了button1 点击了button2 点击了button4