jquery实现预览提交的表单代码分享

2020-05-17 06:20:06易采站长站整理

    </tr> 
    <tr> 
    <td><label for=”subscribe”> Subscribe Us : </label></td> 
    <td><input type=”checkbox” id=”subscribe” name=”subscribe” value=”yes”></td> 
    </tr> 
    <tr> 
    <td></td> 
    <td><input type=”submit” value=”submit”></td> 
    </tr> 
    </tbody> 
    </table> 
    </fieldset> 
    </form> 
<script src=”../../js/jquery-1.9.1.min.js”></script>
<link rel=”stylesheet” type=”text/css” href=”previewForm/previewForm.css” />
<script src=”previewForm/previewForm.js”></script>


JavaScript Code



<script> 
$(document).ready(function() { 
    $(‘#myform’).previewForm(); 
}); 
</script>


previewForm.js



(function($){
 $.fn.previewForm = function(options){
  var form_settings = $.extend({
   identifier         : ‘label’,
   show_password        : true,
   extratext    : ‘Do You Want To submit’,
   yes  : ‘yes’,
   no  : ‘no’,
   title  : ‘Please preview’   
  }, options);
   var dia_log; 
   var renderBUTTON;
   var this_frm;
   this_frm = $(this);
 $(this).submit(function (){


 if($(‘#pfomdata’).length){
      return true;
     }
  
  dia_log=””;
  var needle_cnfrm;
  if(this.id.length > 0){ needle_cnfrm = ‘#’+this.id+’ label’; }
  else  { needle_cnfrm = ‘.’+$(this).attr(‘class’)+’ label’; }
 $(needle_cnfrm).each(function(i,val) {
  if($(this).text().length >2){
 what_t= $(‘#’+$(this).attr(‘for’)) ;
 switch(what_t.prop(‘type’)){
 case ‘password’:
 if(!form_settings.show_password)
  dia_log +=$(this).text() + ” your selected password<br/>”;
 else