123456$("p").bind("mouseenter mouseleave",function(){alert("ok");})$("p").live("mouseenter mouseleave",function(){alert("ok");})
delegate用於事件委托,也是綁定過JavaScript或者jQuery添加的DOM元素事件。
123$("div").delegate("p","click",function(){alert("p");})
點擊div下面的P執行alert;
而on是在1.7之後新增的,是把bind,live,delegate全部合並在壹起了,
123$("div").on("click","p",function(){ alert(1); })
不需要事件委托的時候把P去掉就會變成點擊div觸發了。
個人建議根據版本來使用,語法其實都差不多,如果妳是用1.7版本以上就建議用on,畢竟bind,live,delegate這些將來都會遺棄了,如有錯誤,請指出。順便吐槽壹下樓上的回答,不走心啊