我正在使用此代码仅在某些页面上运行此js。
$("body#action_new").ready(function() {
console.log($("body#action_new"));
console.log($("body#action_new").length);
console.log("code is running");
}
即使body#action_new不存在,代码仍在运行。
两个console.logs打印出:
[]
0
code is running
是怎么回事?
“.size()方法在功能上等同于.length属性;但是,.length属性是首选,因为它没有函数调用的开销。” http://api.jquery.com/size/ – Interrobang 2012-01-31 08:35:17
@Interrobang我希望有人会纠正我...... – Rafay 2012-01-31 08:44:03