我有与多个控件关联的标注标签,当它们中的任何一个都出错时应该变为红色。jquery为特定类型的儿童设置类
<tr>
<th>
<asp:Label for="test">jquery will make my class as updnValidationErrorLabel</asp:Label>
</th>
<td > this text is right
<asp:TextBox class='textboxWide taskListCheckPreVital' />
</td>
<td>this is wrong text hence it has updnValidationErrorInput
<asp:TextBox class='dummyclass updnValidationErrorInput'/></td>
</tr>
我想这种做法,但不知道为什么mainparent儿童元素不带班updnValidationErrorInput
//if my sturcture has updnValidationErrorInput
$('.updnValidationErrorInput').each(function() {
// go to tr element
var mainParent = $(this).parents('tr:first');
// under tr element find updnValidationErrorInput
if(mainParent.children('.updnValidationErrorInput').length > 0){
// set label which has for attribute with updnValidationErrorLabel
mainParent.children('label').attr('for').removeClass().addClass('updnValidationErrorLabel');
}
});
任何帮助将不胜感激显示。
请格式化代码。 – AMIT 2010-09-03 23:59:15
-1表示格式不正确,代码不可读。 – 2010-09-04 00:01:03
没有-1票。 – 2010-09-04 00:53:04