We were originally a very long form form with many options. Customer feedback is not friendly enough and easy to see. Therefore, improvements are made to achieve multi-step progress and multiple submissions implementation (in fact, there is only one form submission).
Implementation idea: Load the form's options into multiple divs, one shows, the others hide .
The effect is as follows:
1. JavaScript code
<script type="text/javascript" src="js/jquery.js"></script><script type="text/javascript" src="js/jquery-powerFloat.js"></script><link rel="stylesheet" href="css/powerFloat.css" type="text/css" /><script type="text/javascript"> $(function() { $(".pwdTrigger").powerFloat({ eventType : "focus", targetMode : "remind", targetAttr : "placeholder", position : "2-1" }); });</script><script type="text/javascript"> function one() { if (confirm("Confirm commit?")) { $("#one").hide(); $("#two").show(); $("#grxx").attr("class","current_prev"); $("#zjxx").attr("class","current"); } } function two() { if (confirm("Confirm commit?")) { $("#two").hide(); $("#three").show(); $("#grxx").attr("class","done"); $("#zjxx").attr("class","current_prev"); $("#qzxx").attr("class","current"); } } function three() { if (confirm("Confirm commit?")) { $("#three").hide(); $("#four").show(); $("#grxx").attr("class","done"); $("#zjxx").attr("class","done"); $("#qzxx").attr("class","current_prev"); $("#qzfs").attr("class","current"); } } function reone() { if (confirm("Confirm return?")) { $("#one").show(); $("#two").hide(); $("#grxx").attr("class","current"); $("#zjxx").attr("class",""); } } function retwo() { if (confirm("Confirm return?")) { $("#three").hide(); $("#two").show(); $("#grxx").attr("class","current_prev"); $("#zjxx").attr("class","current"); $("#qzxx").attr("class",""); } } function rethree() { if (confirm("Confirm return?")) { $("#four").hide(); $("#three").show(); $("#grxx").attr("class","done"); $("#zjxx").attr("class","current_prev"); $("#qzxx").attr("class","current"); $("#qzfs").attr("class","last");; } }</script>2. CSS code
<style type="text/css">.flow_steps ul li { float:left; height:23px; padding:0 40px 0 30px; line-height:23px; text-align:center; background:url(img/barbg.png) no-repeat 100% 0 #E4E4; font-weight:bold;}.flow_steps ul li.done { background-position:100% -46px; background-color:#FFEDA2;}.flow_steps ul li.current_prev { background-position:100% -23px; background-color:#FFEDA2;}.flow_steps ul li.current { color:#fff; background-color:#990D1B;}.flow_steps ul li.last { background-image:none;}</style>3. HTML code
<body> <table> <tr> <td> <div> <ul style="list-style-type:none"> <li id="grxx">Personal information</li> <li id="zjxx">Disclaimer information</li> <li id="qzxx">Sign up information</li> <li id="qzfs">Certification method</li> </ul> </div> </td> </td> </tr> <tr><td> <form action=""> <div id="one"> <table align="center"> <tr> <td>Location location: </td> <td><input type="text" placeholder="Please enter the location of your household registration" /></td> </tr> <tr> <td>Chinese surname: </td> <td><input type="text" placeholder="Please enter Chinese surname" /></td> </tr> <tr> <td>Chinese name: </td> <td><input type="text" placeholder="Please enter Chinese name" /></td> </tr> <tr> <td>Identity card number: </td> <td><input type="text" placeholder="Please enter ID number" /></td> </tr> <tr> <td colspan="2"> <button type="button" onclick="one()">Submit</button> </td> </tr> </table> </div> <div> id="two" style="display: none"> <table align="center"> <tr> <td>Pass number</td> <td><input type="text" placeholder="Please enter the ID number" /></td> </tr> <tr> <td>Expiration date until </td> <td><input type="text" placeholder="Please enter the ID number" /></td> </tr> <tr> <td>Contact number</td> <td><input type="text" placeholder="Please enter the ID number" /></td> </tr> <tr> <td>Contact number</td> <td><input type="text" placeholder="Please enter the contact number, it is recommended to be a mobile phone number" /></td> </tr> <tr> <td> <button type="button" onclick="two()">Submit</button> </td> <td> <button type="button" onclick="reone()">Previous</button> </td> </tr> </table> </div> <div id="three" style="display: none"> <table align="center"> <tr> <td>Sign-name category</td> <td><input type="text" placeholder="please enter the signature-name category" /></td> </tr> <tr> <td>Go to the place</td> <td><input type="text" placeholder="please enter the destination" /></td> </tr> <tr> <td>Visa Type</td> <td><input type="text" placeholder="Please enter the visa type" /></td> </tr> <tr > <td > <button type="button" onclick="three()">Submit</button> </td> <td> <button type="button" onclick="retwo()">Previous</button> </td> </td> </tr> </table> </div> <div id="four" style="display: none"> <table align="center"> <tr> <td>Evidence collection method</td> <td><input type="text" placeholder="Please enter the evidence collection method" /></td> </tr> <tr > <td > <button type="button" onclick="">Submit</button> </td> <td> <button type="button" onclick="rethree()">Previous</button> </td> </tr> </tr> </table> </div> </form> </td> </td> </tr></table></body></html>
Source code download: http://xiazai.VeVB.COM/201606/yuanma/JavaScript-formshow(VeVB.COM).rar
The above is all about this article, and I hope it will be helpful for everyone to learn JavaScript programming.