在盘旋tr时改变整个表背景

时间:2015-02-11 10:18:26

标签: html html-table

我有一张带有背景图片和两张<td>的桌子。 我基本上想在悬停其中一个td时更改整个表背景图像。有什么方法可以做到吗?

2 个答案:

答案 0 :(得分:0)

使用jQuery:

$( function() {
  $('#OneOfTheTD').click( function() {
    $(this).parent("table").toggleClass("class-with-other-background");
  } );
} );

答案 1 :(得分:0)

HTML:

<table id="ch">
            <tr>
                <td>hsadkj</td>
                <td>asdy</td>
                <td>jghsdk</td>
            </tr>
            <tr>
                <td onmouseover="chan()">dsjh</td>
                <td>ksahd</td>
                <td>kldfjh</td>
            </tr>
        </table>

JS:

function chan()
{
    document.getElementById("ch").style.backgroundImage="url";
}