那些js中的高逼格的简写

判断元素是否存在

if($(".robot").length)$(".robot").dance();

代替if,适合简短没有else的情况

$(".robot").length && alert(1);

 三目代替if..else

$(".robot").length ? alert(1) : alert(2);
$(".robot").length ? alert(1) : null;

 

posted @ 2016-05-18 20:19  hpyou  阅读(626)  评论(0编辑  收藏  举报