Attribute Value: This attribute contains single value script which works when mouse clicked on the element. Also the script in href won’t get executed if the time difference is short. You may prefer to use the EventTarget.addEventListener() method instead, since it's more flexible. // Get the button, and when the user clicks on it, execute myFunction document.getElementById("myBtn").onclick = function() {myFunction()}; /* myFunction toggles between adding and removing the show class, which is used to hide and show the dropdown content */ 除了执行顺序不同以外,还有一个非常大的区别那就是onclick只在你快速点击并放开才会被执行,如果你点击一个区域,很迟才放开,那么onclick是不会执行的,如下图就是我点击div两秒以后松开的结果。 addEventListener can add multiple events, whereas with onclick this cannot be done. The OnMouseOver, OnLoad, and OnClick JavaScript functions are explained--with examples--in this tutorial. onclick can be added as an HTML attribute, whereas an addEventListener can only be added within

ontouchstart vs onclick