A. DOM進階 02 表格滑鼠經過高亮,dom02

來源:互聯網
上載者:User

A. DOM進階 02 表格滑鼠經過高亮,dom02
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<table id="table1" border="1px" width="400px" cellpadding="0" cellspacing="0">
    <thead>
    <tr>
        <td>ID</td>
        <td>姓名</td>
        <td>操作</td>
    </tr>
    </thead>
    <tbody>
    <tr>
        <td>1</td>
        <td>大卡</td>
        <td></td>
    </tr>
    <tr>
        <td>2</td>
        <td>leo</td>
        <td></td>
    </tr>
    <tr>
        <td>3</td>
        <td>莫莫</td>
        <td></td>
    </tr>
    <tr>
        <td>4</td>
        <td>aaa</td>
        <td></td>
    </tr>
    <tr>
        <td>5</td>
        <td>bbb</td>
        <td></td>
    </tr>
    <tr>
        <td>6</td>
        <td>ccc</td>
        <td>ccc</td>
    </tr>
    </tbody>
</table>
<script type="text/javascript">
    var oTab=document.getElementById("table1");
    var i=0;
    var oldColor;
    for(i=0;i<oTab.tBodies[0].rows.length;i++)
    {
        oTab.tBodies[0].rows[i].style.background=i%2?"#ccc":"";//給雙行添加背景
         oTab.tBodies[0].rows[i].index=i;
        oTab.tBodies[0].rows[i].onmouseover=function()
        {
            oldColor=this.style.backgroundColor;//儲存原來的背景顏色
            this.style.background="yellow";


       };
        oTab.tBodies[0].rows[i].onmouseout=function()
        {
            this.style.background=this.index%2?oldColor:"";//恢複
        };


    }


</script>
</body>

</html>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.