繁体   English   中英

使用jQuery更改选项卡

[英]Changing tabs with jQuery

我正试图在点击时更改td的背景颜色。 这就是我目前对JavaScript的看法:

$(document).ready(function() {
$('#leftHoldNav table td').click(function(){
    var $this = $(this);
    $this.addClass('highlight');
    $this.parent().siblings('table').find('td').removeClass('highlight');
});
});

这就是我对HTML的看法:

    <div id="leftHoldNav">
    <center>
    <table cellpadding="0" cellspacing="0">
    <tr>
        <td onclick="loadPage('../about/info.php','#mainWrapLoad','../about/')" class="highlight">Info</td>
        <td onclick="loadPage('../about/kcintl.php','#mainWrapLoad','../about/')" class="">KC Int'l</td>
        <td onclick="loadPage('../about/board.php','#mainWrapLoad','../about/')" class="">Board</td>
        <td onclick="loadPage('../about/dcon.php','#mainWrapLoad','../about/')" class="">D-Con</td>
    </tr>
    </table>
    </center>
    </div>

它不起作用,任何人都知道为什么?

http://jsbin.com/inogov/1/edit

你不需要回到parent那里,留在siblings身边。

$this.siblings('td').removeClass('highlight');

你去:

$('#leftHoldNav table td').click(function(){
    var $this = $(this);
    $this.addClass('highlight').siblings('td').removeClass('highlight');
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM