HOME  >>>  HTML整理ノート  >>> DHTML --  基本編  応用編

タブの作成

HTML要素の識別

tagName

ID属性

class属性

name属性

上のタブをクリックすれば、その内容がここに表示されます。
メッセージ表示

Sample Source......................................................................>>>

<style TYPE="text/css"><!--
    .style1 {border-left:2px solid white;
            border-top:2px solid white;
            border-right:2px solid black;
            border-bottom:2px solid black;}
    .style2 {border:0px;}
--></style>

<script language="JavaScript"><!--
var oldel = null;
function TabOpen(c){
    if(null != oldel){
        oldel.className = "style1";    //スタイルを元に戻す
        oldel.style.backgroundColor = "";
    }
    var el = event.srcElement;     //クリックしたタブを識別する
    el.style.backgroundColor = c; //タブの色を設定
    el.className = "style2";         //スタイルを変更し、タブの枠線を消す
    tab.style.backgroundColor = c; //データ表示領域もタブと同じ色に
    oldel = el;        //現在のタブを記憶しておく
   
    if(c == "linen")tab.innerHTML = d1.innerHTML;
    if(c == "lavender")tab.innerHTML = d2.innerHTML;
    if(c == "mistyrose")tab.innerHTML = d3.innerHTML;
    if(c == "lightcyan")tab.innerHTML = d4.innerHTML;
}

function Mover(obj,n){    //マウスオーバー時
    obj.style.color = "red";
    if(n == 1){
        mes.innerText = "要素のtagNameプロパティを利用";}
    if(n == 2){
        mes.innerHTML = "要素のidプロパティを利用";}
    if(n == 3){
        mes.innerHTML = "要素のclassNameプロパティを利用";}
    if(n == 4){
        mes.innerHTML = "要素のnameプロパティを利用";}
}
function Mout(obj){         //マウスアウトしたら
    obj.style.color = "";
}
//--></script>
</head>

<body>
<table border="3" bgcolor="#000000" cellspacing="0">
<tr><td>
    <table style="background-color:silver;"
        cellspacing="0" cellpadding="3">
<tr>
    <td colspan="4" align="center">HTML要素の識別</td>
</tr>
<tr>
  <td id="td1" class="style1"
    onmouseover="Mover(this,1);" onmouseout="Mout(this);"
    onclick="TabOpen('linen');">tagName</td>
  <td id="td2" class="style1"
    onmouseover="Mover(this,2);" onmouseout="Mout(this);"
    onclick="TabOpen('lavender');">ID属性</td>
  <td id="td3" class="style1"
    onmouseover="Mover(this,3);" onmouseout="Mout(this);"
    onclick="TabOpen('mistyrose');">class属性</td>
  <td id="td4" class="style1"
    onmouseover="Mover(this,4);" onmouseout="Mout(this);"
    onclick="TabOpen('lightcyan');">name属性</td>
</tr>
<tr>
    <td id="tab" colspan="4" width="400" height="200">
    上のタブをクリックすれば、その内容がここに表示されます。</td>
</tr>
<tr>
    <td id="mes" colspan="4">メッセージ表示</td>
</tr>
</table>
</td>
</tr>
</table>

<div id="d1" style="display:none">
    ・・・(省略)・・・
<div id="d4" style="display:none">


end(最終更新:12/11/12)