我使用AJAX更新容器。在性能方面哪個更好?僞代碼:哪個更好,刷新後還是live()(jQuery)?
$.post('get_something.php',function(data){
$('#container').html(data).find('a').bind('click',function(){
console.log('Doh!');
});
});
或者這個?
$('#container a').live('click',function(){
console.log('Doh!');
});
$.post('get_something.php',function(data){
$('#container').html(data);
});
第一個腳本 – mgraph 2012-02-07 12:43:06
組合使用的第二與'上()'。建議並在性能最好使用'上()'代替'綁定()'和' live()'from jQuery 1.7 - http://api.jquery.com/on/ – MarkSmits 2012-02-07 12:43:43
如果有一個控制的數量,比如說1-5,不更新的元素,那麼'bind()'優先?這個事件會在沒有在DOM周圍徘徊的情況下被觸發? – 2012-02-07 13:00:45