判断元素是否存在
if($(".robot").length)$(".robot").dance();
代替if,适合简短没有else的情况
$(".robot").length && alert(1);
三目代替if..else
$(".robot").length ? alert(1) : alert(2); $(".robot").length ? alert(1) : null;