| 編程(Programming)是編定程序的中文簡稱,就是讓計(jì)算機(jī)代碼解決某個(gè)問題,對(duì)某個(gè)計(jì)算體系規(guī)定一定的運(yùn)算方式,使計(jì)算體系按照該計(jì)算方式運(yùn)行,并最終得到相應(yīng)結(jié)果的過程。為了使計(jì)算機(jī)能夠理解(understand)人的意圖,人類就必須將需解決的問題的思路、方法和手段通過計(jì)算機(jī)能夠理解的形式告訴計(jì)算機(jī),使得計(jì)算機(jī)能夠根據(jù)人的指令一步一步去工作,完成某種特定的任務(wù)。這種人和計(jì)算體系之間交流的過程就是編程。 【實(shí)例名稱】 帶鏈接的滾動(dòng)字幕 【實(shí)例描述】 滾動(dòng)文本是新聞顯示的重要手段,如果要在滾動(dòng)的文本中實(shí)現(xiàn)鏈接,則需要?jiǎng)討B(tài)設(shè)置鏈接文本和鏈接地址。本例學(xué)習(xí)如何實(shí)現(xiàn)帶鏈接的滾動(dòng)字幕。 【實(shí)例代碼】 <html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>標(biāo)題頁-本站(www.xue51.com)</title>
</head>
<body>
<script language="JavaScript1.2">
var marqueewidth=400 //設(shè)置marquee的寬度 (in pixels)
var marqueeheight=20 //設(shè)置marquee的高度 (in pixels, 該參數(shù)只適用于Netscape)
var speed=4 //設(shè)置marquee滾動(dòng)的速度(數(shù)值越大速度越快)
//設(shè)置marquee顯示內(nèi)容,使用標(biāo)準(zhǔn)的HTML語法。
var marqueecontents='<strong><big>歡迎支持中國搜索引擎
<a href="http://www.baidu.com">百度一下</a> 找到自己想找的 信息</big></strong></font>'
if (document.all)
document.write('<marquee scrollAmount='+speed+'
style="width:'+marqueewidth+'">'+marqueecontents+'</marquee>')
function regenerate(){
window.location.reload();
//重新加載頁面
}
function regenerate2(){
if (document.layers){
setTimeout("window.onresize=regenerate",450);
//窗體改變大小時(shí)重載
intializemarquee();
}
}
function intializemarquee(){
//使用nobr控制顯示的字符個(gè)數(shù)
document.cmarquee01.document.cmarquee02.document.
write('<nobr>'+marqueecontents+'</nobr>');
document.cmarquee01.document.cmarquee02.document.close();
thelength=document.cmarquee01.document.
cmarquee02.document.width; //獲取層的寬度
scrollit();
//實(shí)現(xiàn)字體的滾動(dòng)
}
function scrollit(){
if (document.cmarquee01.document.cmarquee02
.left>=thelength*(-1)){
document.cmarquee01.document.cmarquee02.left-=speed;
setTimeout("scrollit()",100);
//定時(shí)器實(shí)現(xiàn)不停的調(diào)用
}
else{
document.cmarquee01.document.cmarquee02.left=marqueewidth;
scrollit();
}
}
window.onload=regenerate2;
</script>
<ilayer width=&{marqueewidth}; height=&{marqueeheight};
name="cmarquee01">
<layer name="cmarquee02"></layer>
</ilayer>
</body>
</html>
【運(yùn)行效果】 
【難點(diǎn)剖析】 本例的重點(diǎn)主要包括如何動(dòng)態(tài)添加鏈接和如何實(shí)現(xiàn)文本的滾動(dòng)=代碼中使用了一個(gè)全局變量“marqueecontents來保存鏈接內(nèi)容和地址:文本的滾動(dòng)通過定時(shí)器不斷地調(diào)用“scrollit”方法實(shí)現(xiàn)。 【源碼下載】 如果你不愿復(fù)制代碼及提高代碼準(zhǔn)確性,你可以點(diǎn)擊:帶鏈接的滾動(dòng)字幕 進(jìn)行本實(shí)例源碼下載
使用編程語言寫的程序,由于每條指令都對(duì)應(yīng)計(jì)算機(jī)一個(gè)特定的基本動(dòng)作,所以程序占用內(nèi)存少、執(zhí)行效率高。 |