javascript 控制 table tr display block 顯示模式時,只對第一個儲存格有效,trblock

來源:互聯網
上載者:User

javascript 控制 table tr display block 顯示模式時,只對第一個儲存格有效,trblock

有一個簡單的 table:


 

<table > <tr > <th>編號</th> <th>類型</th> <th>詳細</th> <th>建立時間</th> <th>修改時間</th> <th>操作</th> </tr>  <tr> <td>5</th> <td>TECH</th> <td>測試內容</th> <td>2014−01−10 16:56:31</th> <td>−−</th> <td>修改 刪除</th> </tr>  <tr id="id_dync" style="display:none"> <td colspan=6> <div id=xxxx >測試內容</div> </td> </tr> </table>

希望通過 javascript 控制 第三 行的 tr 隱顯狀態:

var tr_modifing = document.getElementById( "id_dync" );tr_modifing.style.display = "block";

這種將 style.display 設定成 block 後, 會出現 只對第一個單元格 td 有效情況:


原因是 將 tr.style.display = “block” 後, 該 tr 就不是普通的 【表格】之【行】了, 而就像普通的 div 一樣普通的塊, 所以下面的 

<td colspan=6 >

也會隨著失效, 正確的做法是 

var tr_modifing = document.getElementById( "id_dync" );tr_modifing.style.display = "";

即 將 tr 的 顯示模式設定為 空,這個屬性dispaly後面不加任何的東西,很奇怪,這樣就相容了Firefox和IE了。



聯繫我們

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