因此,如果我想在单击按钮时发生某些事情,我可以这样做:
<!-- EXAMPLE A-->
<input type="button" onclick="alert('hello world');">
或者我可以
<!-- EXAMPLE B-->
<input type="button" id="clickme">
<script>
$('#clickme').on("click",function(){alert('hello world');});
</script>
或者当然任何变化(on change, on hover)和快捷方式(.click() .change())都是可能的......
除了 A 更短之外,还有什么区别?哪个更好?为什么?
我注意到,当我使用.html()动态向站点添加元素(如按钮)时,B 不适用于这个新创建的按钮,我需要使用 A...
任何见解都会有所帮助!