最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Removing novalidate to a particular field - Stack Overflow

programmeradmin2浏览0评论

How can i remove the property of required to the Second Element "Second Name" ?

Here is my Code :

<form action="#" novalidate>
  First Name:
       <input type="text" name="first" required>
  Second Name : 
       <input type="text" name="second" required>
  <input type="submit">
</form>

How can i remove the property of required to the Second Element "Second Name" ?

Here is my Code :

<form action="#" novalidate>
  First Name:
       <input type="text" name="first" required>
  Second Name : 
       <input type="text" name="second" required>
  <input type="submit">
</form>

Share Improve this question asked Dec 10, 2014 at 9:44 AngularAngularAngularAngularAngularAngular 3,7795 gold badges27 silver badges42 bronze badges 2
  • what do you mean by to the Second one "Class" – Kartikeya Khosla Commented Dec 10, 2014 at 9:48
  • Updated for your understanding – AngularAngularAngular Commented Dec 10, 2014 at 9:48
Add a ment  | 

5 Answers 5

Reset to default 3

You can set required property to false

$("input[name=class]").prop("required", false);
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
Name: <input type="text" name="name" required>
Class: <input type="text" name="class" required>
<input type="submit">
</form>

Using jQuery you can do:

$('input[name=second]').prop('required', false);

Example

Try using .removeAttr().

$('input[name="class"]').removeAttr('required')

Try this:

$('input[type="text"][name="second"]').prop('required', false);

it just removes the required property on the target element which has the name "second".

you can use the

removeAttribute mand:

First set ID's for the inputs.

I set it to the same value as the name.

Next removeAttribute

document.getElementById("class").removeAttribute("required"); 

This should do the trick ;)

Here, have a fiddle:

Fiddle

发布评论

评论列表(0)

  1. 暂无评论