jquery siblings()没有选择器不工作

Mat*_*ips 2 html jquery selector

简单表:

    <table class="schedules">
        <th colspan="2">Saved Schedules</th>
        <tr>
            <td>Winter 2011 </td>           
        </tr>
        <tr>
            <td>Winter 2011 (2) </td>           
        </tr>
        <tr>
            <td>May Term 2011 </td>         
        </tr>
        <tr>
            <td>Fall Term 2011</td>         
        </tr>       
    </table>
Run Code Online (Sandbox Code Playgroud)

jQuery的:

    <script type="text/javascript">
        $(document).ready(function(){
            $(".schedules td").click(function(){
                $(this).css("background-color","blue")
                $(this).siblings().css("background-color","white");         
            });
        });     
    </script>
Run Code Online (Sandbox Code Playgroud)

这应该将选定的单元格切换为背景颜色:蓝色,将兄弟姐妹切换为背景颜色:白色,但是当我单击每个单元格时,只需更改为背景颜色:蓝色,而其他单元格则根本不会更改.

sup*_*led 5

<td>是堂兄弟,而不是兄弟姐妹.td的父母(<tr>兄弟姐妹)是兄弟姐妹.你可以像这样修改jquery ......

http://jsfiddle.net/superuntitled/fb4g7/

    $(document).ready(function(){
        $(".schedules tr").click(function(){
            $(this).find('td').css("background-color","blue")
            $(this).siblings().find('td').css("background-color","white");         
        });
    }); 
Run Code Online (Sandbox Code Playgroud)