dedecms文章页差评调用
<div class='bad' title='差评' id="{dede:field.id/}"> <span id='bad{dede:field.id/}'>差评:{dede:field.badpost/}</span> </div>
如果想点击好评、差评起作用,加上下面的JS即可
<script type="text/javascript" src="{dede:global.cfg_basehost/}/member/templets/js/j.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("div[class*='good'],div[class*='bad']").bind("click", function(){
var type = $(this).attr('class'),aid = $(this).attr('id');
var saveId = getCookie('diggid');
if(saveId != null)
{
var saveIds = saveId.split(',');
var hasId = false;
j = 1;saveId = '';
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 false; }
else saveId += ','+aid;
setCookie('diggid',saveId,1);
}
else
{
setCookie('diggid',aid,1);
}
$.ajax({type: 'POST',url: "{dede:global.cfg_basehost/}/plus/feedback.php",
data: "formurl=caicai&action="+type+"&aid="+aid,
dataType: 'text',
success: function(result){$("#"+type+aid).html(result);}
});
});
});
//读写cookie函数
function getCookie(c_name)
{
if (document.cookie.length > 0)
{
c_start = document.cookie.indexOf(c_name + "=")
if (c_start != -1)
{
c_start = c_start + c_name.length + 1;
c_end = document.cookie.indexOf(";",c_start);
if (c_end == -1)
{
c_end = document.cookie.length;
}
return unescape(document.cookie.substring(c_start,c_end));
}
}
return null
}
function setCookie(c_name,value,expiredays)
{
var exdate = new Date();
exdate.setDate(exdate.getDate() + expiredays);
document.cookie = c_name + "=" +escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString()); //使设置的有效时间正确。增加toGMTString()
}
function postBadGood(type,id){}
</script>