JQuery中的CSS问题 [英] CSS Issue in JQuery
本文介绍了JQuery中的CSS问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
为什么$('#table> tr')选择器不匹配? (总是返回0)
我试图将颜色应用到表的行使用以下代码。它不工作,但我不明白为什么。
$ b
HTML :
p $ p>< table id =tblSampleborder =1cellpadding =0cellspacing =0width =300px>
< tr>
< td> 1< / td>
< td> 1< / td>
< / tr>
< tr>
< td> 2< / td>
< td> 2< / td>
< / tr>
< / table>
JQuery :
$(#tblSample> tr)css(background-color,grey);
解决方案
您错过了难以捉摸的 tbody
元素 。
您可以这样做:
$ tblSample> tbody> tr)css(background-color,gray);
或:
$(#tblSample tr)。css(background-color,grey);
Possible Duplicate:
Why does $('#table > tr') selector not match? (always return 0)
I tried to apply color to rows of a table using the following code. It doesn't work, but I don't understand why. Could someone explain why or point me in the right direction?
HTML:
<table id="tblSample" border="1" cellpadding="0" cellspacing="0" width="300px">
<tr>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>2</td>
<td>2</td>
</tr>
</table>
JQuery:
$("#tblSample > tr").css("background-color", "gray");
解决方案
You're missing the elusive tbody
element.
You can do this:
$("#tblSample > tbody > tr").css("background-color", "gray");
or this:
$("#tblSample tr").css("background-color", "gray");
这篇关于JQuery中的CSS问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文