模板
<script language="javascript" type="text/javascript"> function postDigg(ftype,aid) { var taget_obj = document.getElementById('diggNum'+aid); var saveid = GetCookie('diggid'); //我所有赞过的文章id //alert(saveid); if(saveid != null) { var saveids = saveid.split(','); var hasid = false; saveid = ''; j = 1; for(i=saveids.length-1;i>=0;i--) { if(saveids[i]==aid && hasid) continue; //我顶过 else { if(saveids[i]==aid && !hasid) hasid = true; saveid += (saveid=='' ? saveids[i] : ','+saveids[i]); j++; if(j==20 && hasid) break; if(j==19 && !hasid) break; } } if(hasid) { //alert("您已经顶过该帖,请不要重复顶帖 !"); //如果点击后,被赞过.则不需要更新统计,直接改变颜色 $('#digg'+aid).addClass("icon-heart-on"); return; } else saveid += ','+aid; SetCookie('diggid',saveid,1); } else { //如果cookie中无记录,则记录 SetCookie('diggid',aid,1); } myajax = new DedeAjax(taget_obj,false,false,'','',''); var url = "{dede:global.cfg_phpurl/}/digg_ajax_list.php?action="+ftype+"&id="+aid; myajax.SendGet2(url); DedeXHTTP = null; } </script>{dede:arclist row='6' orderby='id' titlelen='100'} <span id="diggNum[field:id/]"> <a href="javascript:"class=" text-bbb text-16" onclick="javascript:postDigg('good',[field:id/])"><span id="digg[field:id/]" class="icon-heart2 "> </span> </a>[field:goodpost/] </span> {/dede:arclist}
css
.icon-heart2{ background: url(../images/bg-main.png) -22px 5px no-repeat; } .icon-heart2:hover{ background: url(../images/bg-main.png) 2px 4px no-repeat; } .icon-heart-on{ background: url(../images/bg-main.png) 2px 4px no-repeat; }然后在,plus中新建立一个digg_ajax_list.PHP文件,内容为