[英]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.