jQuery implements the button click On All and Anti menu check box and check box text box form validation

  • 2020-06-19 09:48:27
  • OfStack

jQuery implements button click on all/Reverse checkbox/check box text box form validation

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  <base href="<%=basePath%>">
  <title>My JSP 'index.jsp' starting page</title>
  <meta http-equiv="pragma" content="no-cache">
  <meta http-equiv="cache-control" content="no-cache">
  <meta http-equiv="expires" content="0">  
  <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
  <meta http-equiv="description" content="This is my page">
  <link rel="stylesheet" type="text/css" href="styles.css">
  <script type="text/javascript" src="jquery-1.4.js"></script>
  <script type="text/javascript">
     // button 
     alert("This is my JSP page");
     // The text box 
     // A drop-down box 
     // Radio buttons 
     // Check box 
      var str="";// define 1 An array    
      $('input[name="checkbox"]:checked').each(function(){// Traverse every 1 A name for interest The check box for the selected execution function    
      str+=$(this).val();// Adds the selected value to the array chk_value In the   
     // Future generations 
     // All don't choose 
     // The selected 
        $(this).attr("checked", !$(this).attr("checked")); 
     // Future generations / The selected 
     // Form validation 
      return false;
     }else if($("#age").val()==""){
      return false;
     alert(" Name: "+$("#name").val()+"  "+" age "+$("#age").val() );
  <!--  button  -->
  <input type="button" value=" confirm " id="but"/><br>
  <!--  The text box  --> 
  <input type="text" name="text" id="te" /><input type="button" id="btext" value=" The values "><br>
  <!--  A drop-down box  -->
  <select id="sel">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
  <!--  Radio buttons  -->
  <input type="radio" name="radiobutton" id="uradio1" value="1"> 1 
  <input type="radio" name="radiobutton" id="uradio2" value="2"> 2
  <input type="radio" name="radiobutton" id="uradio3" value="3"> 3
  <!--  Check box  -->
  <input type="checkbox" name="checkbox" value="1"> 1 
  <input type="checkbox" name="checkbox" value="2"> 2 
  <input type="checkbox" name="checkbox" value="3"> 3 
  <input type="checkbox" name="checkbox" value="4"> 4
  <input type="button" id="ucheck" value=" determine ">
  <!--  Select all and unselect the check box  -->
   <input type="checkbox" name="checkItems" id="checkItems" value=" Future generations / All don't choose "/> Future generations / All don't choose 
    <input type="checkbox" name="items" value=" football "/> football 
    <input type="checkbox" name="items" value=" basketball "/> basketball 
    <input type="checkbox" name="items" value=" swimming "/> swimming 
    <input type="checkbox" name="items" value=" Sing a song "/> Sing a song 
    <input type="button" name="checkall" id="checkall" value=" Future generations " />
    <input type="button" name="checkall" id="checkallNo" value=" All don't choose " />
    <input type="button" name="checkall" id="check_revsern" value=" The selected " />
  <!--  Form validation  -->
  <form action="">
      Name: <input type="text" id="name"><span id="nameid" style="color:#f00;"> Name must not be empty! </span><br>
      Age: <input type="text" id="age"/><span id="ageid" style="color:#f00;"> Age cannot be empty! </span> <br> 
    <input type="button" id="ubu" value=" determine " />

Rookie the first release, if there is wrong also hope to point out

This is the end of this article, I hope you enjoy it.

Related articles: