Home > Web Front-end > JS Tutorial > JQuery form validates whether the radio button is selected Experience summary

JQuery form validates whether the radio button is selected Experience summary

小云云
Release: 2018-01-10 09:43:02
Original
2392 people have browsed it

This article mainly introduces the experience summary of verifying whether the radio button is selected before submitting the JQuery form form and verifying when deleting records. It is very good and has reference value. Friends who need it can refer to it.

Go up first Three renderings:

JQuery form validates whether the radio button is selected Experience summary
JQuery form validates whether the radio button is selected Experience summary
JQuery form validates whether the radio button is selected Experience summary

##These functions may be often needed in Java Web development. Although they are very simple, they are very practical functions. They are recorded here so as not to forget them.

1. Let’s talk about verification before form submission: it is often used in the background (here is unified verification after submission, please refer to my other article for timely verification

http://blog.csdn. net/jianzhonghao/article/details/52503431)

1.1 After submitting through the submit button, it will jump to the corresponding path according to the attribute action="path" of the form. At this time, add an onsubmit =" to the form. return check()" attribute, check() makes the verification function we want to write, as shown below:

 <form action="路径" onsubmit="return check()" method="POST">
Copy after login

1.2 The check() function is as follows (verify whether the name is If you fill in the gender of the radio button and check it) $('#notice'), just write p and add an id attribute

<script type="text/javascript"> 
 function check(){
  var name = $(&#39;#name&#39;).val().trim();
  var gender=$(&#39;input:radio[name="gender"]:checked&#39;).val();
  if(!name){
   $(&#39;#notice&#39;).text(&#39;客服名称不能为空!&#39;).show();
   return false;
  }else if(!gender){
   $(&#39;#notice&#39;).text(&#39;请选择客服性别!&#39;).show();
   return false;
  }
  else{
   return true;
  }
 }
</script>
<p id="notice" style="font-size: 30px;color:red;margin-top: 15px;" ></p>
Copy after login

1.3 Finally Let’s talk about the issue of confirming whether to delete when deleting

<input type="image" src="删除图标的路径" title="删除" onclick="{if(confirm(&#39;确定删除吗?&#39;)){javascript:document:delfrom_${ServerInfo.id };return true;}return false;}">
分开写实际就是
if(confirm(&#39;确定删除吗?&#39;)){
 {javascript:document:delfrom_${ServerInfo.id };
 return true;
}
 return false;
Copy after login

Related recommendations:


Jquery practical application, judging radio , selelct, whether the checkbox is selected and the selected value

Angular.JS determines whether the checkbox is selected and displays it in real time

jquery determines the checkbox Whether to select

The above is the detailed content of JQuery form validates whether the radio button is selected Experience summary. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template