jQuery attr方法-获得修改元素属性值
<div>\
<span class="is-Attention" data-isAttention="'+item.isAttention+'" data-userid="'+item.userid+'" data-nickname="'+item.nickname+'" >'+(item.isAttention==1? "已关注" : "关注")+'</span>\
</div>\
//关注
$(".is-Attention").click(function(){
var that = this
var AttentionVariable=$(that).attr("data-isattention")
var userid=$(this).attr("data-userid")
var nickname=$(this).attr("data-nickname")
if(AttentionVariable==0){
sendReq("addAttention","post","/shop/userAttention/query",{attentonuserid:userid,attentonusername:nickname},function(res){
// console.log(res)
if(res.status==1){
// $(that).addClass("ele-hidden")
// $(that).siblings(".revenue-ranking-followed").removeClass("ele-hidden")
$(that).text("已关注")
//把属性data-isattention的值修改为1
$(that).attr("data-isattention","1")
layer.msg("关注成功",{icon:1})
}else{
layer.msg("关注失败",{icon:2})
}
})
}else{
//取消关注
sendReq("cancelAttention","post","/shop/userAttention/query",{attentonuserid:userid},function(res){
// console.log(res)
if(res.status==1){
layer.msg("已取消关注",{icon:1})
//成功取消关注后 修改对应值
$(that).text("关注")
//把属性data-isattention的值修改为0
$(that).attr("data-isattention","0")
}else{
layer.msg("取消关注失败",{icon:2})
}
})
}
});