我正在用 jQuery 启动一个项目。
你的 jQuery 项目中有哪些陷阱/错误/误解/滥用/误用?
没有意识到性能影响并过度使用选择器而不是将它们分配给局部变量。例如:-
$('#button').click(function() {
$('#label').method();
$('#label').method2();
$('#label').css('background-color', 'red');
});
而不是:-
$('#button').click(function() {
var $label = $('#label');
$label.method();
$label.method2();
$label.css('background-color', 'red');
});
Or 链接效果更好:-
$('#button').click(function() {
$("#label").method().method2().css("background-color", "red");
});
I found this当我意识到调用堆栈如何工作时,这是一个启发性的时刻。
编辑:在评论中纳入建议。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)