2010-08-25 56 views
0
$("#commentForm").validate({ 
      rules: { 
       insurance1$ucBuildingInsurance$txtOtherReasonDescription: required 
} 
}); 

我现在的剧本是这样来验证一个文本框txtOtherReasonDescription.Ideally我想用$取代insurance1 $ ucBuildingInsurance $ txtOtherReasonDescription()语法,这样的控件ID不固定的。无论如何,这可以实现吗?jQuery验证softcode文本框中的名称

回答

1

可以使用这样的选择添加规则:

$("#commentForm").validate(); 
$("input[id$='txtOtherReasonDescription']").rules("add", { required: true }); 

既然你在ASP.Net是,无论是id$=name$=在这里工作,但概念是建立valdiation的形式,然后使用.rules("add", rulesToAdd)将规则附加到匹配的元素。