JQUERY点击变色再次点击还原

点击TABLE中的td变色再次点击还原,如何实现。想加个flag判断不知加在哪,或者还有更好的方法。详细点谢谢
$('#select1 td').each(function(){
$(this).click(function(){

if(flag == true){
$(this).css("background-color","white");

}else {
$(this).css("background-color", "#96b8ff");

}

        });

做个样式来toggle下就行了,之前写给你的额示例就有了:http://ask.csdn.net/questions/387475
而且直接绑定事件就行了,不需要each。。


<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.1.min.js"></script>
<style>td.selected{background:#96b8ff;}</style>

<table border="1">
    <tr><td>1111</td><td>1111</td></tr>
    <tr><td>2222</td><td>2222</td></tr>
    <tr><td>3333</td><td>3333</td></tr>
</table>
<script>
    $('td').click(function () { $(this).toggleClass('selected')})
</script>