1.typeof判断
如果存在某个属性 (“#aid”).attr(“rel”) 会返回 rel的值,如果不存在 rel属性则会返回”undefined”
使用 if(typeof( (“#aid”).attr(“rel”) 会返回 rel的值,如果不存在 rel属性则会返回”undefined” 使用 if(typeof( (“#aid”).attr(“rel”))==”undefined”) 即可
if (typeof($(this).attr("hasclicked")) == "undefined"){
//code
$(this).attr('hasclicked',true);
}