編程(Programming)是編定程序的中文簡稱,就是讓計算機代碼解決某個問題,對某個計算體系規定一定的運算方式,使計算體系按照該計算方式運行,并最終得到相應結果的過程。為了使計算機能夠理解(understand)人的意圖,人類就必須將需解決的問題的思路、方法和手段通過計算機能夠理解的形式告訴計算機,使得計算機能夠根據人的指令一步一步去工作,完成某種特定的任務。這種人和計算體系之間交流的過程就是編程。 【實例名稱】 鏈接的注釋 【實例描述】 當用戶移動鼠標到某鏈接時,可以為鏈接提供簡要說明。本例以滾動提示的方式,為鏈接設置注釋。 【實例代碼】 <html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>標題頁-本站(www.xue51.com)</title>
</head>
<body>
<script>
if (!document.layers&&!document.all)
event="test"
//顯示提示的方法
function shownote(current,e,text)
{
//IE瀏覽器的情況下
if (document.all&&document.readyState=="complete"){
//滾動顯示提示內容
document.all.tip.innerHTML='<marquee
style="border:1px solid black">'+text+'</marquee>'
//根據鼠標位置設置提示位置
document.all.tip.style.pixelLeft=event.clientX+
document.body.scrollLeft+10
document.all.tip.style.pixelTop=event.clientY+document.body.scrollTop+10
document.all.tip.style.visibility="visible"
}
//Netscape瀏覽器的情況下
else if (document.layers){
document.tip.document.nstip.document.write('<b>'+text+'</b>')
document.tip.document.nstip.document.close()
document.tip.document.nstip.left=0
currentscroll=setInterval("scrolltip()",100)
document.tip.left=e.pageX+10
document.tip.top=e.pageY+10
document.tip.visibility="show"
}
}
//隱藏提示的方法
function hidenote()
{
if (document.all)
document.all.tip.style.visibility="hidden" //隱藏div的顯示
else if (document.layers){
clearInterval(currentscroll)
document.tip.visibility="hidden"
}
}
//提示信息的滾動方法
function scrolltip()
{
if (document.tip.document.nstip.left>=
-document.tip.document.nstip.document.width)
document.tip.document.nstip.left-=5
else
document.tip.document.nstip.left=150
}
</script>
<div id="tip" style="position:absolute;clip:rect(0 150 50 0);
width:150px;background-color:#99FF99; top: 31px;
left: 103px; visibility: hidden; height: 13px">
</div>
<a href="http://google.com" onMouseOver="shownote(this,event,
'國外第一搜索引擎,歡迎使用')" onMouseOut="hidenote()">國外搜索</a>
</body>
</html>
【運行效果】 
【難點剖析】 本例的重點是div的隱藏和顯示,還有提示信息的滾動功能。本例中提供三個方法“shownote”、“hidenote”和“scrolltip”!皊hownote’’方法顯示div的提示信息,并通過“scrolltip’’滾動顯示提示文本。當鼠標離開鏈接時使用“hidenote”方法隱藏注釋。 【源碼下載】 如果你不愿復制代碼及提高代碼準確性,你可以點擊:鏈接的注釋 進行本實例源碼下載
使用編程語言寫的程序,由于每條指令都對應計算機一個特定的基本動作,所以程序占用內存少、執行效率高。 |