搜吧的这种帖子是怎么发的?(刷新一次换一张图)
2013-11-10
展开全部
每刷新一次页面就顺序更换一张图片的js特效<P align=left><FONT size=2><B>制作方法:<BR> <BR>第一步 </B>将下面代码粘贴到网页的<head>与</head>间的任何位置:</FONT>)DE R/a `moZ
<P align=left><FONT size=2><script language="JavaScript"><BR>var imgnum=5 //设置要显示的图片数,本例总共是5张。<BR>function dispimg() //将几乎整个js脚本定义成一个函数dispimg(),为的是可以在<body>与<body>间随意地调用脚本、安排图片的显示位置。<BR>{<BR>var caution = false<BR>function setCookie(name, value, expires, path, domain, secure)<BR>{<BR>var curCookie = name + "=" + escape(value) +<BR>((expires) ? "; expires=" + expires.toGMTString() : "") +<BR>((path) ? "; path=" + path : "") +<BR>((domain) ? "; domain=" + domain : "") +<BR>((secure) ? "; secure" : "")<BR>if (!caution || (name + "=" + escape(value)).length <= 4000)<BR>document.cookie = curCookie<BR>else if (confirm("Cookie exceeds 4KB and will be cut!"))<BR>document.cookie = curCookie<BR>}<BR><BR>function getCookie(name)<BR>{<BR>var prefix = name + "="<BR>var cookieStartIndex = document.cookie.indexOf(prefix)<BR>if (cookieStartIndex == -1)<BR>return null<BR>var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)<BR>if (cookieEndIndex == -1)<BR>cookieEndIndex = document.cookie.length<BR>return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))<BR>}<BR><BR>function deleteCookie(name, path, domain)<BR>{<BR>if (getCookie(name))<BR>{<BR>document.cookie = name + "=" + <BR>((path) ? "; path=" + path : "") +<BR>((domain) ? "; domain=" + domain : "") +"; expires=Thu, 01-Jan-70 00:00:01 GMT"<BR>}<BR>}<BR><BR>function fixDate(date)<BR>{<BR>var base = new Date(0)<BR>var skew = base.getTime()<BR>if (skew > 0)<BR>date.setTime(date.getTime() - skew)<BR>}<BR><BR>var now = new Date()<BR>fixDate(now)<BR>
Qd0}y5T;k&u/d now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000)<BR>var visits = getCookie("counter")<BR>if (!visits)<BR>visits = 1<BR>else<BR>{<BR>visits = parseInt(visits) + 1<BR>};<BR>visits=((visits>imgnum)?visits=1:visits);<BR>setCookie("counter", visits, now)<BR>document.write("<img src=" ,visits ,".jpg border=0><br><br><font size=2>共有 ",imgnum," 张图片,这是第 " ,visits ," 张</font>");/*这里src=后面放图片地址,只写到图片所在文件夹名为止,图片的文件名由脚本自动填写。图片应连续编号,例如:1.jpg,2.jpg,...等*/<BR>//上面有document...的这一行在不清楚js语法时,切不可随意打回车键擅自排版,以免破坏js语句的连续性导致脚本出错。<BR>} //函数dispimg()结束。<BR></script><BR> <BR><B>第二步</B> 将下面这行代码粘贴到网页的<body>与</body>之间需要显示图片特效的地方:<BR> <BR><script>dispimg();</script></FONT>
<P align=left><FONT size=2><script language="JavaScript"><BR>var imgnum=5 //设置要显示的图片数,本例总共是5张。<BR>function dispimg() //将几乎整个js脚本定义成一个函数dispimg(),为的是可以在<body>与<body>间随意地调用脚本、安排图片的显示位置。<BR>{<BR>var caution = false<BR>function setCookie(name, value, expires, path, domain, secure)<BR>{<BR>var curCookie = name + "=" + escape(value) +<BR>((expires) ? "; expires=" + expires.toGMTString() : "") +<BR>((path) ? "; path=" + path : "") +<BR>((domain) ? "; domain=" + domain : "") +<BR>((secure) ? "; secure" : "")<BR>if (!caution || (name + "=" + escape(value)).length <= 4000)<BR>document.cookie = curCookie<BR>else if (confirm("Cookie exceeds 4KB and will be cut!"))<BR>document.cookie = curCookie<BR>}<BR><BR>function getCookie(name)<BR>{<BR>var prefix = name + "="<BR>var cookieStartIndex = document.cookie.indexOf(prefix)<BR>if (cookieStartIndex == -1)<BR>return null<BR>var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)<BR>if (cookieEndIndex == -1)<BR>cookieEndIndex = document.cookie.length<BR>return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))<BR>}<BR><BR>function deleteCookie(name, path, domain)<BR>{<BR>if (getCookie(name))<BR>{<BR>document.cookie = name + "=" + <BR>((path) ? "; path=" + path : "") +<BR>((domain) ? "; domain=" + domain : "") +"; expires=Thu, 01-Jan-70 00:00:01 GMT"<BR>}<BR>}<BR><BR>function fixDate(date)<BR>{<BR>var base = new Date(0)<BR>var skew = base.getTime()<BR>if (skew > 0)<BR>date.setTime(date.getTime() - skew)<BR>}<BR><BR>var now = new Date()<BR>fixDate(now)<BR>
Qd0}y5T;k&u/d now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000)<BR>var visits = getCookie("counter")<BR>if (!visits)<BR>visits = 1<BR>else<BR>{<BR>visits = parseInt(visits) + 1<BR>};<BR>visits=((visits>imgnum)?visits=1:visits);<BR>setCookie("counter", visits, now)<BR>document.write("<img src=" ,visits ,".jpg border=0><br><br><font size=2>共有 ",imgnum," 张图片,这是第 " ,visits ," 张</font>");/*这里src=后面放图片地址,只写到图片所在文件夹名为止,图片的文件名由脚本自动填写。图片应连续编号,例如:1.jpg,2.jpg,...等*/<BR>//上面有document...的这一行在不清楚js语法时,切不可随意打回车键擅自排版,以免破坏js语句的连续性导致脚本出错。<BR>} //函数dispimg()结束。<BR></script><BR> <BR><B>第二步</B> 将下面这行代码粘贴到网页的<body>与</body>之间需要显示图片特效的地方:<BR> <BR><script>dispimg();</script></FONT>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询