开发者

jQuery validation softcode the textbox name

$("#commentForm").validate({
            rules: {
                insurance1$ucBuildingInsurance$txtOtherReasonDescription: required
}
});

My current script looks like this to validate a textbox txtOtherReasonDescription.Ideally I wo开发者_StackOverflowuld like to replace insurance1$ucBuildingInsurance$txtOtherReasonDescription with $() syntax so the control id is not hardcoded. Is there anyway this can be achieved?


You can add the rule using a selector like this:

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

Since you're in ASP.Net, either id$= or name$= works here, but the concept is set up the valdiation on the form, then attach a rule to the matched elements using .rules("add", rulesToAdd).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜