如果你的主页中需要随机显示图片或者链接banner你该怎么实现呢?我们介绍使用Javascript来实现这样的效果! 下面是一个随机显示五条Banner的代码你可以自己定义的 <script language=javascript> <! var b_num = var b=new Array(); function init_item(){ thiswidth = thisheight = thissrc = thishref = thisborder = thisalt = thisunder = thisgrade= thistarget= } function createarray(ba itemnum) { for(var i=; i<itemnum; i++) { ba[i] = new init_item() } } function requestbanner(ba){ sum=; for(i=;i<balength;i++)sum+=ba[i]grade var slump = Mathrandom(); var talet = Mathround(slump*(sum))+; i=; sum=; while(i<balength && sum<=talet){sum+=ba[i]grade;i++;} b=ba[i]; visa = ; if (btarget!=){ visa += <a +bhref+ target=+btarget+>;} else{ visa += <a +bhref+>; } visa += <img src=+bsrc+ height=+bheight; visa += width=+bwidth+ border=+bborder+ alt=+balt+>; visa += </a>; documentwrite(visa); } createarray(bb_num) b b[]src =_//gif // Banner图片路径 b[]href = // Banner链接地址 b[]target=_blank b[]width = b[]height = b[]border = b[]alt = ::::网页教学网:::: // Banner文字提示 b[]under = b[]grade = b b[]src =_//gif b[]href = b[]target=_blank b[]width = b[]height = b[]border = b[]alt = ::::备用域名:::: b[]under = b[]grade = b b[]src =_//gif b[]href = b[]target=_blank b[]width = b[]height = b[]border = b[]alt = ::::技术论坛:::: b[]under = b[]grade = requestbanner(b); // > </Script> 将这段JS代码插入到<body>相应位置 用户可修改相关代码或者增加减少Banner的数量 |