JQuery - Best way of wiring GUI objects to events?

前端 未结 4 1091
长情又很酷
长情又很酷 2020-12-19 22:35

Ever since JQuery came along a few years ago I\'ve been using it in all my client-side scripts. Initially I used the \'$() syntax to grab and manipulate objects this, to me,

4条回答
  •  庸人自扰
    2020-12-19 23:06

    The jQuery version you have can be much smaller as well:

    $(function() {
      $("#myButton").click(function(){
        alert('this is the newer JQuery way of doing things');
      });
    });
    

    I'd go with this or any other unobtrusive route (not inline handlers), there are just fewer issues overall, and maintenance can be much easier. Remember with this route there can be no JavaScript in your page, it can be loaded and cached once by your client meaning faster page loads as well.

    There are many things you just can't do properly (or cross-browser) inline as well, for example the very useful mouseenter and mouseleave (so they don't fire when entering a child) events are only available inline in IE.

提交回复
热议问题