js處理表格對table進行修飾

來源:互聯網
上載者:User

js處理表格

1、行顏色間隔顯示
css樣式:兩個選取器
複製代碼 代碼如下:
<style type="text/css">
.one{
background-color:#33ffcc;
}
.two{
backgound-color:#ffff66;
}
</style>
<script type="text/javascript">
function trcolor()
//控制間隔行顏色顯示不同
{
var tabNode = document.getElementsByTagName("table")[0];
//擷取table節點
var trs = tabNode.rows;
//擷取table中的所有的行
for(var x=1; x<trs.length;x++)
{
if(x%2 == 1)
trs[x].className ="one";
else
trs[x].className ="two";
}
}

//通過onload方法,在網頁載入完成後,運行trcolor方法,實現表格的間隔行顏色。
window.onload = function()
{
trcolor();
}
</script>

2、滑鼠移動到某一行,改行顏色加亮,移開後恢複原來顏色
複製代碼 代碼如下:
<style type="text/css">
.over{
background-color:##00ff00;
}
<style>

<script type="text/javascript">
var name;
function trMouse()
{
var tabNode = document.getELementsByTagName("table")[0];
//通過for迴圈,對每個tr標籤加上onmouseover與onmouseout屬性
for(var x=0;x<trs[x].length;x++)
{
trs[x].onmouseover = function()
{
name=this.className;
this.className="over";
}
tes[x].onmouseout = function()
{
this.className = name;
}
}
}
</script>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.