多表组合查询(三)前后台交互js

2012/09/19 1840点热度 0人点赞 0条评论

综合查询(三) 前后台交互js

//验证左右括号是否正确
var kh = function(str) {
   if(/^[\(|\)]*$/.test(str)||str==""){
        return;
    }else{
        alert("您输入的括号非法")
        return ;
    }
}
/**
 * 将字符串中的s1全部换成s2
 * @param {Object} s1  字符串中包含的字符
 * @param {Object} s2  要替换的内容
 */
 String.prototype.replaceAll=function(s1,s2){
      var demo=this
      while(demo.indexOf(s1)!=-1)
          demo=demo.replace(s1,s2);
      return demo;
 }
/**
 * 给Date的原型添加格式化时间的方法
 * @param {Object} format  要格式化的类型
 * @memberOf {TypeName} 
 * @return {TypeName}  格式化以后的时间
 */
Date.prototype.format = function(format) {
    /* 
     * eg:format="YYYY-MM-dd hh:mm:ss"; 
     */
    var o = {
                                                         
        "M+" : this.getMonth() + 1, // month  
        "d+" : this.getDate(), // day  
        "h+" : this.getHours(), // hour  
        "m+" : this.getMinutes(), // minute  
        "s+" : this.getSeconds(), // second  
        "q+" : Math.floor((this.getMonth() + 3) / 3), // quarter  
        "S" : this.getMilliseconds()
    // millisecond  
    }
                                                         
    if (/(Y+)/.test(format)) {
        format = format.replace(RegExp.$1, (this.getFullYear() + "")
                .substr(4 - (RegExp.$1).length));
    }
                                                         
    for ( var k in o) {
        if (new RegExp("(" + k + ")").test(format)) {
            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k]
                    : ("00" + o[k]).substr(("" + o[k]).length));
        }
    }
    return format;
}
/**
 * 给string增加个len ()方法,计算string的字节数
 * @memberOf {TypeName} 
 * @return {TypeName} 
 */
String.prototype.len = function() {
    return this.replace(/[^\x00-\xff]/g, "xx").length;
}
/**
 * 判断指定的string中是否包含指定的字符串subStr
 * @param {Object} string  长字符串
 * @param {Object} subStr 子字符串
 * @param {Object} isIgnoreCase  true 不顾大小写
 * @return {TypeName} 返回true包含,返回false不包含
 */
var strContains = function(string, subStr, isIgnoreCase) {
    //如果不顾大小写全部转成小写
    if (isIgnoreCase) {
        string = string.toLowerCase();
        subStr = subStr.toLowerCase();
    }
    var startChar = subStr.substring(0, 1);
    var strLen = subStr.length;
    for ( var i = 0; i < string.length - strLen + 1; i++) {
        if (string.charAt(i) == startChar) {
            if (string.substring(i, i + strLen) == subStr) {
                return true;
            }
        }
    }
    return false;
}
//将括号去掉
var yzkh=  function(str){
    if(/[(][^()]*[)]/.test(str)){
        str = str.replace(/[(][^()]*[)]/g, '');
        return yzkh(str);
    }else{
        return str;
    }
  }
//如果是成双的括号返回true,不是返回false
var khcdflag=function(str){
    str = yzkh(str);
    return !/[()]/.test(str);
  }
/**
 * 表切换的方法
 * @param {Object} select 当前选项表的select
 * @param {Object} lx  操作类型1表示设定条件,2表示表头设定
 */
var tableChange=function(select,lx){
    var url=path+"/configSearchAction.do?method=findColumnsByTableName";
    var parameter={
          tableName:select.value
     };
    var columnSelect=null;
    if(lx=="1"){
        //获取当前操作的tr内的td对象
        var thisTr=$(select).parent().parent().children();
        //当前操作的字段
        columnSelect=thisTr.eq(3).children().eq(0);
        //逻辑
        var ljys=thisTr.eq(4);
        //获取当前操作的查询条件值的td
        var cxtjz=thisTr.eq(5);
        columnSelect.empty();
        columnSelect.append("<option >请选择...</option>");
    }else if(lx=='2'){
        columnSelect=$("#columnHeader");
        columnSelect.empty();
    }
    //将jquery对象转成dom对象
    var domSelect=columnSelect[0];
    $.ajax({
      url: url,
      data:parameter,
      async:false,
      success: function(data){
         var jsonData=jQuery.parseJSON(data);
         $.each(jsonData,function(index,node){
               if($.browser.msie){ //如果是ie浏览器,则执行以下代码
                   //select在ie中不支持插入往已存在的select中插入option的字符串
                   if(jsonData[index]!=null){
                        var opt=new Option(jsonData[index].showText,jsonData[index].name);
                        opt.type=jsonData[index].type;
                        domSelect.options.add(opt);
                   }
               }else{//非ie浏览器执行下面的代码
                   if(jsonData[index]!=null){
                        var $option=$("<option/>");
                        $option.attr("value",jsonData[index].name);
                        $option.attr("type",jsonData[index].type);
                        $option.append(jsonData[index].showText);
                        columnSelect.append($option);
                   }
               }
         });
     }});
     if(lx=="1"){
       //每次改变后将逻辑关系和条件查询值清空
        ljys.empty();
        cxtjz.empty();
        //动态获取条件表中的数据到表头表中
        $("#tableHeader").empty();
        $("#conditionTable tbody tr").each(function(index,tr){
           //获取当前tr下的td集合
           var $tds=$(tr).children();
           var $tdTableSelect=$tds.eq(2).children().eq(0);
           //判断表头下拉列表中是否包含要插入的值(当前选中的)
           var  a=jQuery.contains($tdTableSelect.find("option:selected")[0],$("#tableHeader")[0]);
           //判断是否是请选择
           var  b=$tdTableSelect.val()=="请选择";
           if(!strContains($("#tableHeader").text(),$tdTableSelect.find("option:selected").text())&&!b)
           {
                $tdTableSelect.find("option:selected").clone().appendTo($("#tableHeader"));
           }
        });
     }
}
/**
 *弹出模板窗口
 */
var openMbWin=function(){
     window.open(path+"/configSearchAction.do?method=findAllTemplate","_blank","height=300,width=400,top=0,left=0,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no");
}
/**
 * 弹出窗口调用方法
                                                         
 */
var setValue=function(mbId,mbName){
     loadMb(mbId);
     $("#showMbText").html("当前使用的模板是:<strong>"+mbName+"</strong>").css("color","red");
}
/**
 * 添加条件
 */
var addTr=function(){
    //创建td
    //逻辑运算td
    var $ljysTd=$("<td/>");
    $ljysTd.append("<select><option value='and'>并且</option><option value='or'>或者</option></select>");
                                                             
    //左括号td
    var $zkhTd=$("<td/>");
    $zkhTd.append("<input type='text' onchange='kh(this.value)' class='khcss'>");
                                                             
    //表td
    var $tableTd=$("<td/>");
    $tableTd.append("<select  onchange='tableChange(this,1)'><option  selected='selected'>请选择</option><option value='FWAQ_DWY_HTINFO'>项目表</option><option value='FWAQ_DWY_WYINFO'>企业表</option><option value='FWAQ_DWY_WYUSERINFO'>人员表</option></select>");
                                                             
    //字段td
    var $columnTd=$("<td/>");
    $columnTd.append("<select onchange='columnChange(this)' style='width:340px'></select>");
                                                             
    //关系td
    var $gxysTd=$("<td/>");
                                                             
    //查询条件值td
    var $cxtjzTd=$("<td/>");
                                                             
    //右括号td
    var $ykhTd=$("<td/>");
    $ykhTd.append("<input type='text' onchange='kh(this.value)' class='khcss'>");
                                                             
    //操作td
    var $oprTd=$("<td/>");
    $oprTd.append("<a onclick='delTr(this)'>删除</a>");
                                                             
    //创建tr并将td追加到tr上
    var  $tr=$("<tr/>");
                                                             
    $tr.append($ljysTd).append($zkhTd).append($tableTd).append($columnTd).append($gxysTd).append($cxtjzTd).append($ykhTd).append($oprTd);
                                                             
    //将tr绑定到table上
    $("#conditionTable").append($tr);
    return $tr;
}
/**
 * 字段切换操作
 * @param {Object} select  当前字段的select
 */
var  columnChange=function(select){
    //获取当前操作的tr内的td对象
    var thisTr=$(select).parent().parent().children();
    //获取当前操作的关系的td
    var ljys=thisTr.eq(4);
    //获取当前操作的查询条件值的td
    var cxtjz=thisTr.eq(5);
    var ykh=thisTr.eq(6);
    //获取到字段的类型
    var type=$(select).find("option:selected").attr("type");
    //逻辑td中要添加的内容
    var strlj="";
    //查询内容td中要添加的内容
    var strcxtjz="";
    //type是string类型的字段
    if(type=="string"){
        strlj="<select><option value='='>等于</option><option value='like'>包含</option></select>";
        strcxtjz="<input type='text'/>";
    }
    else if(type=="int"||type=="num"){
        strlj="<select><option value='='>等于</option><option value='<'>小于</option><option value='>'>大于</option>" +
        "<option value='>='>大于等于</option><option value='<='>小于等于</option></select>";
        strcxtjz="<input type='text'/>";
    }else if(type=="select"){
        strlj="<select><option value='='>等于</option></select>";
        var tableName=thisTr.eq(2).children().eq(0).val();
        var columnName=select.value;
        //同步加载下拉选
        strcxtjz=searchValue(tableName,columnName);
    }else if(type=="qx"){
        strlj="<select><option value='='>等于</option></select>";
    }else if(type=="date"){
        strlj="时间段";   
        strcxtjz="<input type='text' style='width:90px' class='Wdate' onfocus='WdatePicker({skin:&quot;whyGreen&quot;,maxDate:&quot;%y-%M-%d&quot;})'/>至<input type='text' style='width:90px' class='Wdate' onfocus='WdatePicker({skin:&quot;whyGreen&quot;,maxDate:&quot;%y-%M-%d&quot;})'/>";
    }
    //将逻辑内容添加到td里
    ljys.empty();
    ljys.html(strlj);
                                                             
    cxtjz.empty();
    cxtjz.html(strcxtjz);
    ykh.empty();
    ykh.append("<input type='text' class='khcss'>");
                                                             
}
/**
 * 异步加载下拉选的内容
 * @param {Object} cxtjz 字段类型
 * @param {Object} tableName 操作的表
 * @param {Object} columnName 操作的字段
 */
var searchValue=function(tableName,columnName){
    var url=path+"/configSearchAction.do?method=findSeachValueByTableNameAndColumnName";
    var parameter={
          tableName:tableName,
          columnName:columnName
     };
    //创建下拉选
    var $cxtjzSelect=$("<select/>");
    $cxtjzSelect.append("<option >请选择...</option>");
    $.ajax({
      url:url,
      async:false,
      data:parameter,
      success:function(data){
         var jsonData=jQuery.parseJSON(data);//将获取的数据,解析为json
         $.each(jsonData,function(index,node){
             var stroption="<option value='"+jsonData[index].name+"' >"+jsonData[index].value+"</option>";
             $cxtjzSelect.append(stroption);
         });
     }});
    return $cxtjzSelect;
};
/**
 * 删除当前行
 * @param {Object} a 当前点击删除的a标签
 */
var delTr=function(a){
    //转换成jquery对象,并获取到当前行的tr
    var $tr=$(a).parent().parent();
    var columnName=$tr.children().eq(3).children().eq(0).find("option:selected").text();
    var flag=window.confirm("您真的要删除["+columnName+"]查询字段吗?");
    if(!flag){
        return false;
    }
    //删除
    $tr.remove();
    //将表头设定置空
    $("#tableHeader").empty();
    $("#resultHeader").empty();
    return false;
}
/**
 * 获取表头,将表头组装成json字符串
 * @return {TypeName} 返回json串
 */
var findTableHead=function(){
    var headerJson="{";
    $("#resultHeader option").each(function(index,opt){
        var $opt=$(opt);
        if(headerJson=="{"){
            headerJson=headerJson+"'"+$opt.attr("value")+"':'"+$opt.text()+"'";
        }else{
            headerJson=headerJson+",'"+$opt.attr("value")+"':'"+$opt.text()+"'";
        }
                                                                 
    })
    headerJson=headerJson+"}";
    return headerJson;
}
$(document).ready(function(){
   //表头设定,将选中的从左边移到右边
   $("#rightMoveBtn").click(function(){
       $("#resultHeader").append($("#columnHeader  option:selected"));
       $("#resultHeader option:selected").attr("selected",null);
   });
   //表头设定,将选中的从右边移到左边
   $("#leftMoveBtn").click(function(){
       $("#columnHeader").append($("#resultHeader  option:selected"));
        $("#columnHeader option:selected").attr("selected",null);
   });
   //表头设定,置空
   $("#nullBtn").click(function(){
       $("#resultHeader").empty();
   });
   //双击右移
   $("#columnHeader").dblclick(function(){
       $("#resultHeader").append($("#columnHeader  option:selected"));
   });
   //双击左移
   $("#resultHeader").dblclick(function(){
       $("#columnHeader").append($("#resultHeader  option:selected"));
   });
   //保存查询条件到xml中
   $("#saveSearchCondition2Xml").click(function(){
         //获取表头
       var  strHead=findTableHead();
       //要查询的表
       var sqlfromTable="";
       //查询条件{ljys="",zkh=""}
       var  sqlWhere="{";
        $("#conditionTable tbody tr").each(function(index,tr){
            //获取当前tr下的td集合
           var $tds=$(tr).children();
           //获取表名
           var $tableName=$tds.eq(2).children().eq(0);
            var tableName="";
            if(!jQuery.isEmptyObject($tableName))
                  tableName=$tableName[0].value;
           if(!strContains(sqlfromTable,tableName,true)&&tableName!="请选择"){
               if(sqlfromTable==""){
                   sqlfromTable=tableName;
               }else{
                   sqlfromTable=sqlfromTable+","+tableName;
               }
           }
           var sqlCondition=index+"={";
           //获取逻辑td下的select中的值
           var  $ljValue=$tds.eq(0).children().eq(0);
           var ljValue="";
            if(!jQuery.isEmptyObject($ljValue)){
                if($ljValue[0]){//对象不为空
                    ljValue=$ljValue[0].value;
                }
            }
            sqlCondition=sqlCondition+"'ljys'='"+ljValue+"'";
           //获取左括号
           var zkh=$tds.eq(1).children().eq(0).val();
            if(jQuery.isEmptyObject(zkh))
                  zkh="";
           sqlCondition=sqlCondition+",'zkh'='"+zkh+"'";
           //获取表名
           sqlCondition=sqlCondition+",'tableName'='"+tableName+"'";
           //获取字段名
           var $columnName=$tds.eq(3).children().eq(0);
           var columnName=$columnName[0].value;
           if(jQuery.isEmptyObject(columnName))
                  columnName="";
           sqlCondition=sqlCondition+",'columnName'='"+columnName+"'";
            //获取字段类型
           var type=$tds.eq(3).children().eq(0).find("option:selected").attr("type");
                                                                    
           //获取条件值
           var tjz=$tds.eq(5).children().eq(0).val();
           if(jQuery.isEmptyObject(tjz))
                tjz="";
           //获取关系
           var gx=$tds.eq(4).children().eq(0).val();
            if(jQuery.isEmptyObject(gx))
                  gx="";
           sqlCondition=sqlCondition+",'gx'='"+gx+"'";
                                                             
           if(type=="date"){
               var startDate=$tds.eq(5).children().eq(0).val();
               var endDate=$tds.eq(5).children().eq(1).val();
               if(jQuery.isEmptyObject(startDate))
                   startDate="";
               if(jQuery.isEmptyObject(endDate))
                   endDate="";
               sqlCondition=sqlCondition+",'cxtjz'='"+startDate+"|"+endDate+"'";
           }else{
               sqlCondition=sqlCondition+",'cxtjz'='"+tjz+"'";
           }
           //获取右括号
           var ykh=$tds.eq(6).children().eq(0).val();
            if(jQuery.isEmptyObject(ykh))
                   ykh="";
           sqlCondition=sqlCondition+",'ykh'='"+ykh+"'";
           sqlCondition=sqlCondition+"}";
           if(sqlWhere=="{"){
               sqlWhere=sqlWhere+sqlCondition;
           }else{
               sqlWhere=sqlWhere+","+sqlCondition;
           }
        });
       sqlWhere=sqlWhere+"}";
       //设置模板名称
       var mbName=prompt("请输入模板名称","未命名");
       if(!mbName){
          mbName="未命名";
       }
       //创建动态表单,将这些数据发送到后台
       var  $form=$("<form/>").attr({"id":"saveSearchForm","name":"saveSearchForm","method":"post"});
       var timestamp = (new Date()).valueOf();  
       $form.attr("action",path+"/zhSearchAction.do?method=saveSearchCondition&timestamp=" + timestamp);
       //设置模板的名称
       var  $mbName=$("<input/>").attr({"type":"hidden","name":"search_mbName"});
       $mbName.attr("value",mbName);
                                                                
       var $tableHead=$("<input/>").attr({"type":"hidden","name":"search_tableHead"});
       $tableHead.attr("value",strHead);
                                                                
       var $sqlfromTables=$("<input/>").attr({"type":"hidden","name":"search_sqlfromTables"});
       $sqlfromTables.attr("value",sqlfromTable);
                                                                
       var $sqlWhere=$("<input/>").attr({"type":"hidden","name":"search_sqlWhere"});
       $sqlWhere.attr("value",sqlWhere);
       //将文本域添加到表单上
       $form.append($mbName).append($tableHead).append($sqlfromTables).append($sqlWhere);
       //提交表单
       $("body").append($form);//必须追加到body上否则在ie下不能提交
       document.getElementById("saveSearchForm").submit();
   });
   //切换模板
   $("#selectMb").change(function(){
       var id=$("#selectMb").val();
       loadMb(id);
   })
                                                          
                                                           
});
/**
 * 根据模板id加载对应的模板
 * @param {Object} mbId 模板id
 */
var loadMb=function(mbId){
       var url=path+"/configSearchAction.do?method=findTemplateById";
       var parameter={
           id:mbId
       };
    if(mbId!="请选择"){
       $.post(url,parameter,function(data){
          var jsonData=jQuery.parseJSON(data);
          var tableHead=jsonData[0].tableHead;
          resultHeaderH(tableHead);  
          $.each(jsonData[0].trs,function(index,tr){
              var thisTr=null;
              if(index!=0){
                  thisTr=addTr();
              }else{
                  $("#conditionTable tbody tr").slice(1).remove();
                  thisTr=$("#conditionTable tbody tr").eq(0);
              }
                                                                       
              var thisTds= thisTr.children();
                                                                      
              var ljys=tr.ljys,zkh=tr.zkh,tableName=tr.tableName,columnName=tr.columnName,gx=tr.gx,cxtjz=tr.cxtjz,ykh=tr.ykh;
              if(ljys!=""&&ljys!="and"){
                  thisTds.eq(0).children().eq(0).val(ljys);
              }
              if(zkh!=""){
                  thisTds.eq(1).children().eq(0).val(zkh);
              }
              if(tableName!=""){
                  var $select=thisTds.eq(2).children().eq(0).val(tableName);
                  tableChange($select[0],1);
              }
              if(columnName!=""){
//                    var $select=thisTds.eq(3).children().eq(0).val(columnName);使用jquery代码在ie下报错
                      var $select=thisTds.eq(3).children().eq(0);
                     // $select.val(columnName);
                      $select[0].value=columnName;
                      columnChange($select[0]);
              }     
              if(gx!=""){
                      var $select=thisTds.eq(4).children().eq(0).val(gx);
              }
              if(cxtjz!=""){
                     if(cxtjz.indexOf("|")>=0){//时间类型
                         var arr=cxtjz.split("|");
                         thisTds.eq(5).children().eq(0).val(arr[0]);
                         thisTds.eq(5).children().eq(1).val(arr[1]);
                     }else{
                            thisTds.eq(5).children().eq(0).val(cxtjz);
                     }
              }
              if(ykh!=""){
                  thisTds.eq(6).children().eq(0).val(ykh);
              }
          });
          var fromTable=jsonData[0].fromTable;//
       });
     }else{
          $("#conditionTable tbody tr").slice(1).remove();
          $("#conditionTable tbody tr").eq(0).children().eq(2).children().eq(0).children().eq(0).attr("selected","selected");
          tableChange( $("#conditionTable tbody tr").eq(0).children().eq(2).children().eq(0)[0],1);
     }
   }
/**
 * 查询表头回显
 * @param {Object} tableHead
 */
var  resultHeaderH=function(tableHead){
    var select=$("#resultHeader");
    select.empty();
    tableHead=tableHead.replaceAll("'","\"");
    var headJson=jQuery.parseJSON(tableHead);
    for(var key in headJson){
        addOption(select,key,headJson[key]);
    }
}
/**
 * 给select对象添加option选项,兼容ie和其他浏览器
 * @param {Object} select  select的Jquery对象
 * @param {Object} value   option的value值
 * @param {Object} text    option的显示值
 */
var addOption=function(select,value,text){
    if($.browser.msie){
        var opt=new Option(text,value);
        select[0].options.add(opt);
    }else{
        var $option=$("<option/>").attr("value",value).append(text);
        select.append($option);
    }
}
 //点击查询按钮,处理字符串
var searchFn=function(){
       //获取表头
       var  strHead=findTableHead();
       //要查询的表
       var sqlfromTable="";
       var  sqlWhere="where 1=1 ";
       //获取表中tr的数量
       //alert($("#conditionTable tbody tr").length);
       //遍历条件表中的tr
       var flag=false;
       $("#conditionTable tbody tr").each(function(index,tr){
            var sqlCondition="";
            //获取当前tr下的td集合
            var $tds=$(tr).children();
            //获取表名
            var tableName=$tds.eq(2).children().eq(0).val();
                                                                    
            if(!strContains(sqlfromTable,tableName,true)&&tableName!="请选择"){
               if(sqlfromTable==""){
                   sqlfromTable=tableName;
               }else{
                   sqlfromTable=sqlfromTable+","+tableName;
               }
           }
           //前缀
           var prefix="";     
                                                                   
           //获取逻辑td下的select中的值
           var  ljValue=$tds.eq(0).children().eq(0).val();
           if(!jQuery.isEmptyObject(ljValue)){
               sqlCondition=sqlCondition+ljValue;
           }else{
               sqlCondition=sqlCondition+" and ";
           }
           //获取左括号
           var zkh=$tds.eq(1).children().eq(0).val();
           sqlCondition=sqlCondition+" "+zkh;
           //获取字段名
           var $columnName=$tds.eq(3).children().eq(0);//直接用val()取不到
           var columnName=$columnName[0].value;
           //获取字段类型
           var type=$tds.eq(3).children().eq(0).find("option:selected").attr("type");
           //获取条件值
           var tjz=$tds.eq(5).children().eq(0).val();
           if(!tjz&&index==0){
               flag=true;
              // return false;
           }
           //获取关系
           var gx=$tds.eq(4).children().eq(0).val();
           //获取右括号
           var ykh=$tds.eq(6).children().eq(0).val();
           if(columnName=="x.bjzt"){//ht.bjzt
               if($.trim(tjz)=="已标记"){
                   sqlCondition=sqlCondition+"  (ht.bghtbj is not null and ht.bghtbj!='无') ";
               }else if($.trim(tjz="未标记")){
                   sqlCondition=sqlCondition+" (ht.bghtbj is null or ht.bghtbj='无') ";
               }
           }else{
               sqlCondition=sqlCondition+" "+prefix+columnName;
               if(type=="string"||type=="select"){
                  if(gx=="like"){
                     sqlCondition=sqlCondition+" "+gx+" '%"+tjz+"%'";
                  }else{
                     sqlCondition=sqlCondition+gx+" '"+tjz+"'";
                  }
               }
               else if(type=="date"){
                  var startDate=$tds.eq(5).children().eq(0).val();
                  var endDate=$tds.eq(5).children().eq(1).val();
                  if(startDate==null||startDate==""){
                      startDate="1900-01-01";
                  }
                  if(endDate==null||endDate==""){
                      var date=new Date().format("YYYY-MM-dd");
                      endDate=date;
                  }
                  sqlCondition=sqlCondition+" between to_date('"+startDate+"','yyyy,mm,dd')  and  to_date('"+endDate+"','yyyy,mm,dd')";
              }else{
                  sqlCondition=sqlCondition+gx+tjz;
              }
           }
            sqlCondition=sqlCondition+" "+ykh;
           //判断条件值是否存在,如果不存在或者为空则置空
           if(jQuery.isEmptyObject(tjz)||tjz==""||tjz=="请选择..."){
               if(type!="date"){
                    sqlCondition="";
               }
           }
           sqlWhere=sqlWhere+" "+sqlCondition;
        });
       if(!khcdflag(sqlWhere)){
           alert("括号没有成对出现");
           return false;
       }
       //创建动态表单,将这些数据发送到后台
       var  $form=$("<form/>").attr({"id":"subForm","name":"subForm","method":"post"});
       var timestamp = (new Date()).valueOf();  
       $form.attr("action",path+"/zhSearchAction.do?method=searchResultList&timestamp=" + timestamp);
                                                         
       var $tableHead=$("<input/>").attr({"type":"hidden","name":"search_tableHead"});
       $tableHead.attr("value",strHead);
                                                                
       var $sqlfromTables=$("<input/>").attr({"type":"hidden","name":"search_sqlfromTables"});
       $sqlfromTables.attr("value",sqlfromTable);
                                                                
       var $sqlWhere=$("<input/>").attr({"type":"hidden","name":"search_sqlWhere"});
       $sqlWhere.attr("value",sqlWhere);
                                                                
       //将文本域添加到表单上
       $form.append($tableHead).append($sqlfromTables).append($sqlWhere);
       //提交表单
        $("body").append($form);//必须追加到body上否则在ie下不能提交
        document.getElementById("subForm").submit();
}

yxkong

这个人很懒,什么都没留下

文章评论