http://blog.sina.com.cn/s/blog_53b4fd3801000arv.html
第一步 将下面代码粘贴到网页的<head>与</head>间的任何位置:
<script language="JavaScript">var imgnum=5 //设置要显示的图片数,本例总共是5张。 function dispimg() //将几乎整个js脚本定义成一个函数dispimg(),为的是可以在<body>与<body>间随意地调用脚本、安排图片的显示位置。 { var caution = false function setCookie(name, value, expires, path, domain, secure) { var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "") if (!caution || (name + "=" + escape(value)).length <= 4000) document.cookie = curCookie else if (confirm("Cookie exceeds 4KB and will be cut!")) document.cookie = curCookie } function getCookie(name) { var prefix = name + "=" var cookieStartIndex = document.cookie.indexOf(prefix) if (cookieStartIndex == -1) return null var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length) if (cookieEndIndex == -1) cookieEndIndex = document.cookie.length return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex)) } function deleteCookie(name, path, domain) { if (getCookie(name)) { document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") +"; expires=Thu, 01-Jan-70 00:00:01 GMT" } } function fixDate(date) { var base = new Date(0) var skew = base.getTime() if (skew > 0) date.setTime(date.getTime() - skew) } var now = new Date() fixDate(now) now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000) var visits = getCookie("counter") if (!visits) visits = 1 else { visits = parseInt(visits) + 1 }; visits=((visits>imgnum)?visits=1:visits); setCookie("counter", visits, now) document.write("<img src=<?php echo $this->staticDomain('app_renyuxian', 'image')?>xuanchuan/erweima/" ,visits ,".jpg border=0><br><br><font size=2>共有 ",imgnum," 张图片,这是第 " ,visits ," 张</font>");/*这里src=后面放图片地址,只写到图片所在文件夹名为止,图片的文件名由脚本自动填写。图片应连续编号,例如:1.jpg,2.jpg,...等*/ //上面有document...的这一行在不清楚js语法时,切不可随意打回车键擅自排版,以免破坏js语句的连续性导致脚本出错。 } //函数dispimg()结束。 </script> 第二步 将下面这行代码粘贴到网页的<body>与</body>之间需要显示图片特效的地方: <script>dispimg();</script>