使用 jQuery 根据多个子元素的条件设置父元素 css
<tr>
<td class="cat" CategoryId="8">NoChange*: </td>
<td><span class="itm" CategoryId="8">A</span></td>
</tr>
<tr>
<td class="cat" CategoryId="9">Row should be red*: </td>
<td></td>
</tr>
<tr>
<td class="cat">Comments:</td>
<td><span class="itm"></span></td>
</tr>
我想为其中没有项目的类别设置验证。 对于类别 8,它有一个关联的值,因此无需显示 required,而类别 9 没有任何与其关联的项目。因此,其 tr 颜色应设置为红色。 另外,评论应该被完全忽略,因为它没有任何类别ID。 我试图将其设置为
$("tr.cat~tr.itm").children(":not(:has(td))").css("color","red")
<tr>
<td class="cat" CategoryId="8">NoChange*: </td>
<td><span class="itm" CategoryId="8">A</span></td>
</tr>
<tr>
<td class="cat" CategoryId="9">Row should be red*: </td>
<td></td>
</tr>
<tr>
<td class="cat">Comments:</td>
<td><span class="itm"></span></td>
</tr>
I want to set Validation for Category which does not have items in it.
For category 8 it has one value associated hence there is no need to show required where as 9 does not have any item associated with it.hence its tr color should be set to red.
Also comment should be ignored altogether as it is not having any categoryid as such.
I m trying to set it as
$("tr.cat~tr.itm").children(":not(:has(td))").css("color","red")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这将选择前面带有
的
:empty
元素。
然后它遍历回
.prev()
元素并更改颜色。尝试一下: http://jsfiddle.net/4DN6Q/1/
This will select
:empty
<td>
elements that are preceded by a<td class="cat">
.Then it traverses back to the
.prev()
element and changes the color.Try it out: http://jsfiddle.net/4DN6Q/1/
检查 jQuery 验证插件。
Check jQuery validation plugin.