输入字段需要jQuery add [英] jQuery add required to input fields

查看:107
本文介绍了输入字段需要jQuery add的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找使用html5验证自动编写jQuery到我的所有输入字段的方法,但是我无法告诉它在哪里写它。

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);

DEMO FIDDLE

这篇关于输入字段需要jQuery add的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆