织梦DEDECMS顶踩功能修改(非插件)

最近在做一个站时。要用到顶踩功能,网上找了好久,没有找到合适的。只好拿默认模板里里修改了。修改后的效果如下,有需要的朋友 ,可拿去修改使用。

用顶踩功能,就必须在内容页模板<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("您已经表决过,请不要重复点击哦 !"); 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调用代码:

<!-- //顶踩 -->
  <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>
  <!-- //顶踩部份的源码结束 -->

 

 

 

THE END