我很困惑$(文檔)在使用這個作爲我的選擇click event
?任何差異或成本,而不是隻使用父母選擇器? 他們都產生相同的輸出,但是有什麼因素像執行速度?
您可以測試這個FIDDLE
var counter = 0;
使用父選擇
$(".parent").on("click", "button.btn", function(){
$(".parent").append("<button class = 'btn'> new button " + (++counter) + "</button><br />");
});
或$(文件)
$(document).on("click","button.btn",function(){
$(".parent").append("<button class = 'btn'> new button " + (++counter) + "</button><br />");
});
爲了瀏覽起見,請使用父選擇器。 :) 謝謝 – 2015-03-03 03:43:01