[英]Changing tabs with jQuery
I'm attempting at changing the background color of the td's on click. 我正试图在点击时更改td的背景颜色。 This is what I currently have for JavaScript:
这就是我目前对JavaScript的看法:
$(document).ready(function() {
$('#leftHoldNav table td').click(function(){
var $this = $(this);
$this.addClass('highlight');
$this.parent().siblings('table').find('td').removeClass('highlight');
});
});
This is what I have for the HTML: 这就是我对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>
It's not working, anybody have an idea why? 它不起作用,任何人都知道为什么?
http://jsbin.com/inogov/1/edit http://jsbin.com/inogov/1/edit
you don't need to go back to parent
, stay on the siblings
. 你不需要回到
parent
那里,留在siblings
身边。
$this.siblings('td').removeClass('highlight');
There you go: 你去:
$('#leftHoldNav table td').click(function(){
var $this = $(this);
$this.addClass('highlight').siblings('td').removeClass('highlight');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.