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

/**
 * Generic Ajax Checkbox
 * The default action is prevented and submit real request through URL
 */
var ajax_checkbox = function(){
 event.preventDefault();
 var action = $(this);
 var url = action.attr('url');
 var _check = action.prop("checked");
 console.log(_check);
 var op ;
 if(_check){
  op = "1";
 }else{
  op = "0";
 }
 $.get(url + op ,function(json){
  if(json.code == true){
    if(_check){
     action.prop("checked",true);
    }else{
     action.prop("checked",false);
    }
    return true;
   }else{
    return false;
   }
 },'json');
};


/**
 * Crete Root picklist
 */
var picklistinit = function(){
 var _select = $(this);
 var _hidden_id = _select.attr('hidden-id');
 var _un = _select.attr('un');
 var _lovchildren = _select.data('lovtree').c;
 var _rowvalue = _select.data('rowvalue');

$("<OPTION>").append("{__('L_SELECT')}").appendTo(_select);
 for(var _kid in _lovchildren){
  var _lov = _lovchildren[_kid]['lov'];
  $("<OPTION>").val(_lov.lov_id).append(_lov.v).attr('k',_lov.id).attr('is_leaf',_lov.is_leaf).appendTo(_select);
 }
 _select.change(picklistchange);

//Select the list
 if(_rowvalue){
  _select.find("[value="+_rowvalue[0]+"]").prop("selected",true);
  _select.change();
 }
 return true;
};

/**
 * Select pick list
 */
var picklistchange = function (){
 var _select = $(this);
 var _hidden_id = _select.attr('hidden-id');
 var _un = _select.attr('un');

//Remove all the subsequent
 var _lovtree = _select.data('lovtree');
 var _rowvalue = _select.data('rowvalue');

_select.nextAll().remove();

//This is value of Current Select
 var _selected = _select.find(':selected');
 if(_selected.attr('is_leaf')=="{DB::T}"){
  $("#"+_hidden_id).val(_select.val());
  _select.after("<img src='https://www.jb51.net/s.gif'/>");
 }else{
  var _val = _select.val();
  var _k = _selected.attr('k');

//Getting Children list
  if(_lovtree.c[_k].c == undefined){
   return false;
  }
  var _c_lovtree =  _lovtree.c[_k];

var _c_select = $('<SELECT>').data('lovtree',_c_lovtree).
   data('rowvalue',_rowvalue).
   attr('hidden-id',_hidden_id).attr('un',_un).
   attr('name',_un+'_'+_k);
  $("<OPTION>").append("{__('L_SELECT')}").appendTo(_c_select);
  //Building the option list
  for(var _kid in _c_lovtree.c){
   var _lov = _c_lovtree.c[_kid]['lov'];
   $("<OPTION>").val(_lov.lov_id).append(_lov.v).attr('k',_lov.id).attr('is_leaf',_lov.is_leaf).appendTo(_c_select);
   //Insert after
   _select.after(_c_select);
   //Onchange
  }
  _c_select.change(picklistchange);

if(_rowvalue){
   _c_select.find("[value="+_rowvalue[_k]+"]").prop("selected",true);
   _c_select.change();
  }
 }
};

var lookup_new = function(){
 var lookup = $(this);
 var pre_script;
 if(pre_script = lookup.attr("pre_script")){
  var ret = eval(pre_script);
  if(ret==false){
   return false;
  }
 }
 var url = lookup.attr("url");
 if(!url){
  alert('url not set');
  return false;
 }
 var height = lookup.attr('h');
 if(!height){
  height = 600;
 }
 var width = lookup.attr('w');
 if(!width){
  width = 800;
 }
 window.open(url,"pselect","scrollbars=yes,menubar=no,height="+height+",width="+width+",resizable=yes,toolbar=no,location=no,status=no");
 return false;
};

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

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