2013年9月11日 星期三

.live & .bind

.bind 和 .live 最大的差別在於 .bind 僅對於現有的元素進行綁定,之後append 進來的元素就不會有event發生,但.live會有事件發生。
所以.live 重複綁定,會執行很多次。

juery從1.7版本開始將bind(),live()和delegate()方法合併成了on()方法了同樣unbind(),die( )和undelegate()方法也合併成了off()方法

舊版寫法:
$(".choseme").live("click", function(e){ alert("hello"); });
新版寫法:
$(".choseme").on("click", function(e){ alert("hello"); });

沒有留言:

張貼留言