熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

圖片或Banner的隨機顯示

2022-06-13   來源: JSP教程 
如果你的主頁中需要隨機顯示圖片或者鏈接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的數量
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19408.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.