我使用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