![](/img/trans.png)
[英]How to append a button with onclick event that fires a function to a table cell
[英]Append code to function of onclick of button
我有这个按钮<button id='a'></button>
我通过 js document.getElementById('a').onclick=function(){alert('Hello world');}
触发它的点击。 如何将 append 编码到标签内的 function 中,如下所示<button id='a' onclick='this.onclick; alert('hello 2');'></button>
<button id='a' onclick='this.onclick; alert('hello 2');'></button>
除了最初在 HTML 中分配的onclick
处理程序之外,您还可以调用addEventListener
添加更多的click
监听器。这样,当您单击按钮时,两个处理程序都会执行。
document.getElementById('a').addEventListener('click', function() { alert('2'); });
<button id="a" onclick="alert('1')">Test</button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.