jQuery 验证插件:输入与文本区域
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18060131/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery Validate plugin: input vs. textarea
提问by tim peterson
I'm wondering why there is a difference in jQuery Validate plugin's default handling of <input>
vs. <textarea>
. In the demo below, notice that the required
class makes the <input>
required but not the <textarea>
.
我想知道为什么 jQuery Validate 插件的默认处理<input>
与<textarea>
. 在下面的演示中,请注意required
该类生成了<input>
required 而不是<textarea>
.
<form>
<input class='required' />
<textarea class='required' ></textarea>
<button value='submit'>submit</button>
</form>
$('form').validate();
回答by Sparky
It has absolutely nothing to do with input
vs.textarea
.
它与input
vs.完全无关textarea
。
See: http://jsfiddle.net/ZAaPu/2/
见:http: //jsfiddle.net/ZAaPu/2/
It's failing because each input
musthave a unique name
attribute in order for this plugin to work properly. See the "Markup Recommendations" section of the "General Guidelines". Otherwise, only the very first element is validated and all others are ignored.
它失败了,因为每个插件都input
必须有一个唯一的name
属性才能使这个插件正常工作。 请参阅“通用指南”的“标记建议”部分。否则,仅验证第一个元素,忽略所有其他元素。
<form>
<input name="thename" class='required' />
<textarea name="another" class='required'></textarea>
<button value='submit'>submit</button>
</form>
Working DEMO:http://jsfiddle.net/ZAaPu/
工作演示:http : //jsfiddle.net/ZAaPu/
回答by Deepak Biswal
回答by Yu Tem
add name attribut to textarea
将名称属性添加到 textarea
<form>
<input class='required' />
<textarea name='bla-bla' class='required'></textarea>
<button value='submit'>submit</button>
</form>
$('form').validate();