2009-12-13 104 views
0

我找到了jQuery验证插件(http://plugins.jquery.com/project/validate),并认为这将是验证客户端上的表单的好方法。 (我也在做服务器端验证)。该插件希望我为类​​标签中的每个字段指定验证规则。我正在使用我的类标记来设置字段的样式,我可以用其他方式指定规则吗?jquery验证插件,指定规则

例如,这是插件如何jQuery的要我写,如果我要被要求现场:

<input type="text" id="MyText" class="required" /> 

我真的想在像另一个标签指定规则:

<input type="text" id="MyText" class="TextStyle" validation="required" /> 

这是可能的,如果是这样,怎么样?所以,你有两个造型和验证

<input type="text" id="MyText" class="TextStyle required"/> 

+0

你为什么要这么做? DTD中没有'validation'属性。您的HTML无效。 – 2009-12-13 10:51:53

+0

是的,我知道,只是一个例子,我不想发送与CSS类的规则,但阿戈斯表明,你可以使用许多类,所以工作完美。谢谢! – Martin 2009-12-13 11:52:51

回答

0

你能为他们用空格分隔元素指定多个类。

0

恕我直言,是最好从HTML保持验证规则远:

$('#someForm').validate({ 
    rules: { 
     MyText: { 
      required: true 
     } 
    }, 
    messages: { 
     MyText: { 
      required: 'Please fill the MyText field' 
     } 
    } 
}); 

,只是有:

<input type="text" name="MyText" id="MyText" />