简体   繁体   English

仅特定提交按钮的JSP / HTML必填字段

[英]JSP/HTML required fields only for specific submit button

I have table for user with 8 fields to complete fields via input type="text" . 我有8个字段的用户表,通过输入type =“ text”来完成字段。 I have added to 4 fields tag "required" . 我已经添加到4个字段标签“ required” And 4 buttons input type="submit": 和4个按钮输入type =“ submit”:

add
delete
edit
deactivate

The problem is that "required" field is checked for all submit buttons, but I want it to be checked only when "add" button is pushed. 问题是所有提交按钮都选中了“必填”字段,但是我希望仅在按下“添加”按钮时才选中它。 Is there any way to bind "required" field to specific button? 有什么办法可以将“必填”字段绑定到特定按钮?

Try it please. 请尝试一下。

 $("form input[type=submit]").click(function() { //console.log($(this).val()); if($(this).val()!=="ADD"){ $('form input[type=text]').each(function() { $(this).removeAttr("required"); }); } $("input[type=submit]", $(this).parents("form")).removeAttr("clicked"); $(this).attr("clicked", "true"); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form action='nothing' method='post' name='testform'> <input type="text" id="name" required> <input type="text" id="age" required> <input type='submit' name='add' value='ADD' /> <input type='submit' name='delete' value='DELETE' /> </form> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM