52,780
社区成员
发帖
与我相关
我的任务
分享
<table id="t1">
<a href="1.php">测试</a>
</table>
那就需要判断下当前链接中有没有7/,如果有就不加,木有就加上
$("#t1 a").click(function () {
var link = $(this).attr("href");
var temp = getCookies("srv"+ link);//不同的链接设置不同的cookie的key这样就可以唯一,方便判断
if ((temp == "" || !temp) && link.indexOf("7/") == -1) {
$(this).attr("href", "7/"+ link);
setCookies("srv"+ link, link);
} else {
$(this).attr("href", "+" + link);
}
$("#t1 a").live("click",function(){
var c_name="srv";
var srvVal = getCookie(c_name);
var oldHref = $(this).attr("href");
if(srvVal ==""){
setCookie(c_name,7,10);
$(this).attr("href")= "7/" + oldHref;
}else{
var newHref = (parseInt(srvVal)+1) + ".php";
$(this).attr("href",newHref);
}
})
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 ""
}
//expiredays:过期天数
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())
}