實(shí)例代碼:用JS代碼隨機(jī)修改網(wǎng)頁標(biāo)題
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>標(biāo)題頁</title>
</head>
<body>
<script language="javascript">
//隨機(jī)顯示TITLE
var til = new Array(5);
til[0] = '第一個(gè)標(biāo)題'
til[1] = '第二個(gè)標(biāo)題'
til[2] = '第三個(gè)標(biāo)題'
til[3] = '第四個(gè)標(biāo)題'
til[4] = '第五個(gè)標(biāo)題'
var indextitle = Math.floor(Math.random() * til.length); //獲取一個(gè)隨機(jī)整數(shù)
onload=function chaTitle() {
var curTitle=til[indextitle]; //獲取數(shù)組中的指定項(xiàng)
window.document.title+=" - "+curTitle; //更改當(dāng)前頁的標(biāo)題
}
</script>
</body>
</html>