javascript处理表单示例(javascript提交表单)(3)

var validate_hidden_id =  function(input) {
 var refid = input.attr("hidden-id");
 var field = $("#" + refid + "");
 var msg = field.attr('msg');
 if( !msg ){
  msg = "{__('E_NOT_EMPTY')}";
 }

return field.val() ? true : msg;
};

var data_equals_validate =  function(input) {
 var field;
 var name = input.attr("data-equals");
 field = this.getInputs().filter("[name=" + name + "]");
 return input.val() == field.val() ? true : [name];
};

/**
 * Ajax request through link
 * If confirm is set, confirm before send request
 * Support returi and reload
 * Else show block message
 */
var ajax_link_req = function(){
 var l = $(this);
 var hint = l.attr('hint');
 if(hint){
  var errHint = $(l.attr('hint'));
  errHint.text('').hide();
 }
 //If the confirm message is set, then should be confirmed from client
 if(l.attr('confirm')){
  if(!confirm(l.attr('confirm'))){
   return false;
  }
 }

$.blockUI({ message:"{__('L_PROCESSING')}" });

var pre_script;
 if(pre_script = l.attr("pre_script")){
  var ret = eval(pre_script);
  if(ret==false){
   return false;
  }
 }

var block = l.attr('block');
 if(block != undefined){
  ajaxAutoUnblock = false ;
 }

$.get(l.attr('href'),function(json){
   if(json.code == true){
    var retData = "{__('L_PROCESSED')}!";
    var returi;
    //If success to execute funtion for each
    var successFunc = l.attr('success');
    if(successFunc){
     l.each(window[successFunc]);
    }

if(json.data){
     retData = json.data; 
    }
    //IF Require warning before
    if( l.attr('value') == 'reqonly'){
     alert(retData);
    }else if(returi = l.attr('returi')){
     window.location = returi;
    }
    else if(l.attr('reload')!=undefined){
     window.location.reload();
    }
    else{
     $.blockUI({ message:retData, css:{ cursor:'pointer',padding:'4px',border:'3px solid #CC0000',}, overlayCSS:{ cursor:'pointer' } });
     $(".blockUI").addClass("blockwarn");
    }
   }else{
    //$.unblockUI();
    //Only could support Text errmsg
    if(hint){
     errHint.text(json.data).show();
    }else{
     alert(json.data);
    }
   }},'json');
 return false;
};

/**
 * Supporting the button base navigation
 * Only jump to new href
 */
var btn_nav = function(){
 var input = $(this);
 var href = input.attr("href");
 if(href){
  window.location = href;
 }else{
  alert("Href not set");
 }
 return false;
};

/**
 * Support button base Ajax get method request
 * support returi and reload
 */
var btn_req = function(){
 var input = $(this);
 var href = input.attr("href");

var hint = input.attr('hint');
 if(hint){
  var errHint = $(hint).first();
  if(errHint.size() == 0){
   errHint = $("#pageError");
  }
  errHint.text('').hide();
 }

var block = input.attr('block');
 if(block != undefined){
  ajaxAutoUnblock = false 
 }

$.get(href,function(json){
   if(json.code == true){
   var returi;
   if(returi = input.attr('returi')){
    window.location = returi;
   }
   else if(input.attr("reload")!=undefined){
    window.location.reload();
   }else{
     var retData = "{__('L_PROCESSED')}!";
     if(json.data){
      retData = json.data; 
     }
     $.blockUI({ message:retData,css:{ cursor:'pointer' },overlayCSS:{ cursor:'pointer' } });
    }
   }else{
    if(hint){
     $.unblockUI();
     errHint.html(json.data.errmsg).show();
    }else{
     $.blockUI({ message:json.data.errmsg, css:{ cursor:'pointer',padding:'4px',border:'3px solid #CC0000',}, overlayCSS:{ cursor:'pointer' } });
     $(".blockUI").addClass("blockwarn");
    }
   }
   },'json');
 return false;
};

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgppsz.html