我一直在寻找方法,让jQuery自动编写所需的使用html5验证到我所有的输入字段,但我有麻烦告诉它在哪里写它。
我想接这个电话
<input type="text" name="first_name" value="" id="freeform_first_name"
maxlength="150">
并在结束标记之前自动添加required
<input type="text" name="first_name" value="" id="freeform_first_name"
maxlength="150" required>
我想我可以做一些类似于
$("input").attr("required", "true");
但这并不奏效。任何帮助都非常感激。
使用。attr方法
// syntax
.attr(attribute,value);
.attr("required", true);
// output: required="required"
.attr("required", false);
// output:
使用.prop
// syntax
.prop(property,value)
.prop("required", true);
// output: required=""
.prop("required", false);
// output:
点击这里阅读更多
https://stackoverflow.com/a/5876747/5413283
使用。attr方法
// syntax
.attr(attribute,value);
.attr("required", true);
// output: required="required"
.attr("required", false);
// output:
使用.prop
// syntax
.prop(property,value)
.prop("required", true);
// output: required=""
.prop("required", false);
// output:
点击这里阅读更多
https://stackoverflow.com/a/5876747/5413283