$(".comment").on("click", "#zan_img", function () {
console.log(this.tagName.toLowerCase()); // "a"
var canZan=$(this).attr('zaned');
if (canZan=='c') {
var approvingNum=$(this).parent().next().text();
approvingNum=parseInt(approvingNum)+1;
$(this).parent().next().text(approvingNum);
$(this).attr('zaned','n');
//use ajax to add commentId-user_name into table zaned
var userName=$('#user_name').text();
//alert(userName);
var commentId=$(this).attr('commentId');
addCommentIdUser("userName",commentId);
//alert('ffsfs');
}else{
alert('您已经赞过了');
}
// return false;
});
新添加的div的结构:
<div class="pinglun" style='display:none' id='com_construct'>
<div class="tx"><a href="javascript:"><img src="touxiang" class="img"/></a></div>
<div class="zj">
<span class="wdyhm">用户名</span>
<span class="plnr">评论内容</span>
</div>
<div class="yc">
<a href="javascript:" >
<img src="__ROOT__/Home/Tpl/Public/images/zan.png" border="0" id='zan_img' zaned="c" commentId=""/>
</a>
<span class="zan" value="<{$comment['id']}>">0</span>
</div>
</div>