<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>標題頁</title>
</head>
<body>
<script language="javascript">
//隨機顯示TITLE
var til = new Array(5);
til[0] = '第一個標題'
til[1] = '第二個標題'
til[2] = '第三個標題'
til[3] = '第四個標題'
til[4] = '第五個標題'
var indextitle = Math.floor(Math.random() * til.length); //獲取一個隨機整數
onload=function chaTitle() {
var curTitle=til[indextitle]; //獲取數組中的指定項
window.document.title+=" - "+curTitle; //更改當前頁的標題
}
</script>
<a href="http://www.youweishop.com">有爲商城</a>
本例將改變標題的代碼寫在了“onload”事件中,所以只有在加載頁面的時候,標題纔會改變。可按F5不斷刷新頁面,測試標題欄的隨機標題。
</body>
</html>