下面这段程序是我在网上找到的,但是我测试过之后,图片变换没问题,但是点击链接时却出现问题了,我设了第一幅图是链接3721第二幅图是百度。。。但是无论我点击哪一个图片链接都去不到目标路径而是去到自己的硬盘路径,请问应该怎样修改下面的代码才能实现第一幅图出现时点击就指定链接要去的网站,第二幅图出现时点击就去指定链接的网站呢?谢谢~!
<script language="JavaScript">
<!--
function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr)); }
function FixCookieDate (date) {
var base = new Date(0);
var skew = base.getTime(); // dawn of (Unix) time - should be 0
if (skew > 0) // Except on the Mac - ahead of its time
date.setTime (date.getTime() - skew); }
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break; }
return null; }
// assign expiration date variable for cookie
var expdate = new Date ();
FixCookieDate(expdate);
expdate.setTime(expdate.getTime() + (5 * 60 * 1000)) // 5 minutes
// initialize countimg variable to track images
countimg = (GetCookie("countimg") != null) ? (GetCookie("countimg")-1) : -1
countimg = (countimg <-1) ? -1 : countimg
IMGArray = new Array(3)
if (document.images) {
IMGArray[0] = new Image(205,56)
IMGArray[1] = new Image(205,56)
IMGArray[2] = new Image(205,56) }
// Old browsers get an array of empty strings
else {
IMGArray[0] = ""
IMGArray[1] = ""
IMGArray[2] = "" }
<!-- 改变下面的三个图像的地址及相应的链接地址-->
IMGArray[0].src = "ko.jpg"
IMGArray[0].URL = "http://www.3721.com"
IMGArray[1].src = "ki.jpg"
IMGArray[1].URL = "http://www.baidu.com"
IMGArray[2].src = "kk.jpg"
IMGArray[2].URL = "http://www.9you.com"
function updateIM(countimg) { return countimg; }
// functions for onMouseOver, onMouseOut, onClick event handlers
function Overhref2() { updateIM(countimg)
if (IMGArray[countimg] != null ) {
window.status = IMGArray[countimg].URL; return true; }}
function Outhref2() { window.status = ""; return true; }
function clickhref2() { updateIM(countimg)
if (IMGArray[countimg] != null ) {
location = IMGArray[countimg].URL }}
// Image swapping function
function showIMAGE() { updateIM(countimg++)
if (document.images) {
// Make sure countimg does'nt get too big
if ( countimg > IMGArray.length - 1 ) { countimg = IMGArray.length - IMGArray.length }
document.images.banner.src = IMGArray[countimg].src
exbannerID = setTimeout("showIMAGE()",2500) }}
function setIt2() { updateIM(countimg)
document.cookie = "countimg=" + countimg + "; expires=" + expdate.toGMTString() }
// get cookie countimg onblur, onload
function getIt2() {
countimg = (GetCookie("countimg") != null) ? (GetCookie("countimg")) : 0
updateIM(countimg)
if (exbannerID != null) { clearTimeout(exbannerID); showIMAGE() }}
function initCOOKIES() {
window.onunload = setIt2
window.onfocus = getIt2
window.onblur = setIt2 }
function initBANNER() {
showIMAGE()
cookieID = setTimeout("initCOOKIES()",1000) }
window.onload = initBANNER
// -->
</script>
<a href="" onClick="clickhref2()" onMouseOver="Overhref2();return true;" onMouseOut="Outhref2;return true;"><img src="" name="banner" border="0" ></a>
[此贴子已经被作者于2006-5-13 18:21:28编辑过]