jQuery 添加必需的输入字段 [英] jQuery add required to input fields
本文介绍了jQuery 添加必需的输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在寻找方法让 jQuery 使用 html5 验证自动将所需的内容写入我的所有输入字段,但我无法告诉它在哪里编写它.
I have been searching ways to have jQuery automatically write required using html5 validation to my all of my input fields but I am having trouble telling it where to write it.
我想要这个
<input type="text" name="first_name" value="" id="freeform_first_name"
maxlength="150">
并让它在结束标记前自动添加必需
and have it automatically add required before the closing tag
<input type="text" name="first_name" value="" id="freeform_first_name"
maxlength="150" required>
我以为我可以按照
$("input").attr("required", "true");
但它不起作用.任何帮助是极大的赞赏.
But it doesn't work. Any help is greatly appreciated.
推荐答案
$("input").prop('required',true);
这篇关于jQuery 添加必需的输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文