<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
<head>
<title>選項卡</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
#div1 .active{
background: yellow;
}
#div1 div{
width: 200px;
height: 200px;
background: gray;
display: none;
}
</style>
<script>
window.οnlοad=function(){
var odiv1 = document.getElementById('div1');
var oinp = odiv1.getElementsByTagName('input');
var odiv = odiv1.getElementsByTagName('div');
for(var i=0;i<oinp.length;i++){
oinp[i].index=i; //設置內容切換
oinp[i].onclick = function(){
for (var i =0; i <oinp.length; i++) {
oinp[i].className="";
odiv[i].style.display='none';
};
this.className="active";
odiv[this.index].style.display='block';
}
}
}
</script>
</head>
<body>
<div id="div1">
<input type="button" value="北京" class="active"/>
<input type="button" value="上海"/>
<input type="button" value="深圳"/>
<div style="display:block;">北京是我們的首都。</div>
<div>上海的東方明珠很漂亮。</div>
<div>深圳是世界之窗。</div>
</div>
</body>
</html>
js 選項卡製作
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.