jq 判断节点是否存在某个属性

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/eddy23513/article/details/81510256

1.typeof判断

如果存在某个属性 (“#aid”).attr(“rel”) 会返回 rel的值,如果不存在 rel属性则会返回”undefined”    使用 if(typeof( (“#aid”).attr(“rel”))==”undefined”) 即可

 if (typeof($(this).attr("hasclicked")) == "undefined"){
    //code
    $(this).attr('hasclicked',true);
 }

猜你喜欢

转载自blog.csdn.net/eddy23513/article/details/81510256
今日推荐