用頂踩功能,就必須在內(nèi)容頁模板<HEAD>頭部引入dedeajax2.js文件,引入代碼如下:
<script language="javascript" type="text/javascript" src="{dede:global.cfg_cmsurl/}/include/dedeajax2.js"></script>
<script language="javascript" type="text/javascript">
<!--
function postBadGood(ftype,fid)
{
var taget_obj = document.getElementById(ftype+fid);
var saveid = GetCookie('badgoodid');
if(saveid != null)
{
var saveids = saveid.split(',');
var hasid = false;
saveid = '';
j = 1;
for(i=saveids.length-1;i>=0;i--)
{
if(saveids[i]==fid && hasid) continue;
else {
if(saveids[i]==fid && !hasid) hasid = true;
saveid += (saveid=='' ? saveids[i] : ','+saveids[i]);
j++;
if(j==10 && hasid) break;
if(j==9 && !hasid) break;
}
}
if(hasid) { alert('您剛才已表決過了喔!'); return false;}
else saveid += ','+fid;
SetCookie('badgoodid',saveid,1);
}
else
{
SetCookie('badgoodid',fid,1);
}
myajax = new DedeAjax(taget_obj,false,false,'','','');
myajax.SendGet2("{dede:field name='phpurl'/}/feedback.php?aid="+fid+"&action="+ftype+"&fid="+fid);
}
function postDigg(ftype,aid)
{
var taget_obj = document.getElementById('newdigg');
var saveid = GetCookie('diggid');
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("您已經(jīng)表決過,請不要重復(fù)點擊哦 !"); return; }
else saveid += ','+aid;
SetCookie('diggid',saveid,1);
}
else
{
SetCookie('diggid',aid,1);
}
myajax = new DedeAjax(taget_obj,false,false,'','','');
var url = "{dede:global.cfg_phpurl/}/digg_ajax.php?action="+ftype+"&id="+aid;
myajax.SendGet2(url);
}
function getDigg(aid)
{
var taget_obj = document.getElementById('newdigg');
myajax = new DedeAjax(taget_obj,false,false,'','','');
myajax.SendGet2("{dede:global.cfg_phpurl/}/digg_ajax.php?id="+aid);
DedeXHTTP = null;
}
-->
</script>
樣式:
/*頂踩*/
.newdigg {
height: 51px;
margin: 0 auto;
clear: both;
overflow: hidden;
padding: 10px 0 30px 150px;
}
.newdigg .digg_good {
background: #ff6666;
}
.diggbox {
width: 195px;
height: 51px;
float: left;
margin-right: 8px;
overflow: hidden;
cursor: pointer;
}
.newdigg .digg_good .digg_act {
color: #fff;
}
.diggbox .digg_act {
font-size: 14px;
float: left;
line-height: 31px;
text-indent: 32px;
height: 29px;
overflow: hidden;
font-weight: bold;
}
.newdigg .digg_good .digg_num {
color: #fff;
}
.diggbox .digg_num {
float: left;
line-height: 29px;
text-indent: 5px;
}
.diggbox .digg_percent {
width: 180px;
clear: both;
padding-left: 10px;
overflow: hidden;
}
.diggbox .digg_percent .digg_percent_bar {
width: 100px;
height: 7px;
background: #E8E8E8;
border-right: 1px solid #CCC;
float: left;
overflow: hidden;
margin-top: 3px;
}
.newdigg .digg_good .digg_percent .digg_percent_bar span {
border: 1px solid #999999;
background: #999999;
}
.diggbox .digg_percent .digg_percent_bar span {
display: block;
height: 5px;
overflow: hidden;
background: #000;
}
.diggbox .digg_percent .digg_percent_num {
font-size: 10px;
float: left;
padding-left: 10px;
}
.newdigg .digg_bad {
background:#ff9966;
}
.diggbox {
height: 51px;
float: left;
margin-right: 8px;
overflow: hidden;
cursor: pointer;
}
.newdigg .digg_bad .digg_act {
color: #FFFFFF;
}
.diggbox .digg_act {
font-size: 14px;
float: left;
line-height: 31px;
text-indent: 32px;
height: 29px;
overflow: hidden;
font-weight: bold;
}
.newdigg .digg_bad .digg_num {
color: #fff;
}
.diggbox .digg_num {
float: left;
line-height: 29px;
text-indent: 5px;
}
.diggbox .digg_percent {
width: 180px;
clear: both;
padding-left: 10px;
overflow: hidden;
}
.diggbox .digg_percent .digg_percent_bar {
width: 100px;
height: 7px;
background: #E8E8E8;
border-right: 1px solid #CCC;
float: left;
overflow: hidden;
margin-top: 3px;
}
.newdigg .digg_bad .digg_percent .digg_percent_bar span {
border: 1px solid #999999;
background: #999999;
}
.diggbox .digg_percent .digg_percent_bar span {
display: block;
height: 5px;
overflow: hidden;
background: #000;
}
.diggbox .digg_percent .digg_percent_num {
font-size: 10px;
float: left;
padding-left: 10px;
}
模板頁面html調(diào)用代碼:
<!-- //頂踩 -->
<div class="newdigg" id="newdigg">
<div class="diggbox digg_good" onmousemove="this.style.backgroundPosition='left bottom';" onmouseout="this.style.backgroundPosition='left top';" onclick="javascript:postDigg('good',{dede:field.id/})">
<div class="digg_act">頂一下</div>
<div class="digg_num">({dede:field.goodpost/})</div>
<div class="digg_percent">
<div class="digg_percent_bar"><span style="width:{dede:field.goodper/}%"></span></div>
<div class="digg_percent_num">{dede:field.goodper/}%</div>
</div>
</div>
<div class="diggbox digg_bad" onmousemove="this.style.backgroundPosition='right bottom';" onmouseout="this.style.backgroundPosition='right top';" onclick="javascript:postDigg('bad',{dede:field.id/})">
<div class="digg_act">踩一下</div>
<div class="digg_num">({dede:field.badpost/})</div>
<div class="digg_percent">
<div class="digg_percent_bar"><span style="width:{dede:field.badper/}%"></span></div>
<div class="digg_percent_num">{dede:field.badper/}%</div>
</div>
</div>
</div>
<script language="javascript" type="text/javascript">getDigg({dede:field.id/});</script>
<!-- //頂踩部份的源碼結(jié)束 -->
]]>