情况时这样的:在我本地测试,数据都好好的,没有什么缺失~!但是在真实环境下就会有时有数据缺失的现象~!求指点~!

解决方案 »

  1.   


    这个代码太多了,我是用javascript接收的参数和判断是否是空值~!如果为空则提示并返回,不为空就将参数返回到后台进行插入操作现在的问题是
         1.有的数据保存到数据库中就是空值(空值的数据也就是千分之几吧
         2.参数传到后台变成0了!
      

  2.   

    那我一点一点的贴吧,多了放不下//临时保存
    function saveParts(){//保存变量方法
    var codestr = "";
    var valuestr="";
    var variablestr="";

       if(!subflag){
           alert("输入值有错误,请检查修改!");
           return;
       }
       var f = document.mainForm; //得到表单对象
       var hashMap=new HashMap(); 
       for(var j=0;j<f.length;j++){
        hashMap.put(f[j].id,f[j]);
       }
       var myDate = new Date();
       var s = myDate.getTime(); 
       for(var i=0;i<vcodes.length;i++){
        var mView = document.mainForm.mname;
        var m = document.mainForm.mname.value;
        var eDiv = document.getElementById("div_"+vcodes[i]);
        //将界面所有显示着的变量code拼成字符串
        if(eDiv){
               if(eDiv.style.display=='block'){
                variablestr+=vcodes[i]+";";
                }
                }
        if(vmodes[i]==m){
                if(hashMap.get(vcodes[i]).type=="text"){//输入题或日期时间题或日期题或下拉列表题
                
                 if(hashMap.get(vcodes[i]).value!=""){//表单对象value有值              idstr+=vids[i]+";";//将变量id拼成字符串
                 codestr+=vcodes[i]+";";//将变量code拼成字符串                  valuestr+=hashMap.get(vcodes[i]).value+";";//将变量value拼成字符串              }else{//表单对象value无值
                 if(mView.style.display!='none'){//20120330lyd模块div显示
                 if(eDiv){
                 if(eDiv.style.display=='block'){
                 alert(vcnames[i]+"\n不能为空");//20120408lyd新增
                 return;//20120408lyd新增
                 }
                 }
                
                 }
                 }
                }else if(hashMap.get(vcodes[i]).type=="radio"){//单选题
                 if(mView.style.display!='none'){//20120330lyd
                 if(eDiv){
                 if(eDiv.style.display=='block'){
                 if(isRadio(hashMap.get(vcodes[i]).name)==""){//name为f[j].name的一组单选按钮全部没有选中
                     for(var h=0;h<tcodes.length;h++){
                     if(hashMap.get(vcodes[i]).name==tcodes[h]){
                     alert(tcnames[h]+"\n不能为空");//提示单选的文本题目不能为空
                     return;
                     }
                     }
                     }
                 }
                 }
                 }
                    if(hashMap.get(vcodes[i]).checked){ //单选选中
                  idstr+=vids[i]+";";//将变量id拼成字符串                      codestr+=hashMap.get(vcodes[i]).name+";";//将变量code拼成字符串
                      valuestr+=hashMap.get(vcodes[i]).value+";";//将变量value拼成字符串
                    }
                }else if(hashMap.get(vcodes[i]).type=="checkbox"){//多选题
                 if(mView.style.display!='none'){//20120330lyd
                 if(eDiv){
                 if(eDiv.style.display=='block'){
                 if(isCheckbox(hashMap.get(vcodes[i]).name)==""){//name为f[j].name的一组多选按钮全部没有选中
                     for(var h=0;h<tcodes.length;h++){
                     if(hashMap.get(vcodes[i]).name==tcodes[h]){
                     alert(tcnames[h]+"\n不能为空");//提示单选的文本题目不能为空
                     return;
                     }
                     }
                     }
                 }
                 }
                 }
                    if(hashMap.get(vcodes[i]).checked){ //多选选中
                  idstr+=vids[i]+";";//将变量id拼成字符串                      codestr+=vcodes[i]+";";//将变量code拼成字符串
                      valuestr+=hashMap.get(vcodes[i]).value+";";//将变量value拼成字符串
                    }
                }else if(hashMap.get(vcodes[i]).type=="select-one"){//下拉列表
                 if(hashMap.get(vcodes[i]).value!="-1"){//下拉列表的value不为空
                 idstr+=vids[i]+";";//将变量id拼成字符串
                 codestr+=vcodes[i]+";";//将变量code拼成字符串                  valuestr+=hashMap.get(vcodes[i]).value+";";//将变量value拼成字符串
                 }else{
                 if(mView.style.display!='none'){//20120330lyd
                 if(eDiv){
                 if(eDiv.style.display=='block'){
                 alert(vcnames[i]+"\n不能为空");
                 return;
                 }
                 }
                 }
                 }
                } 
        }
       }
       var user = "<%=user.getUname()%>";
      if(user!="null"&&user!=""){ 
      testMessageBox(event);
      myDate = new Date();
      var e = myDate.getTime(); 
       if(idstr.lastIndexOf(";")!=-1){// 拼最后一个id时,idstr字符串最后一个字符为;
           idstr = idstr.substring(0,idstr.lastIndexOf(";"));// 去掉最后的;字符
       }
       if(codestr.lastIndexOf(";")!=-1){//拼最后一个code时,codestr字符串最后一个字符为;
           codestr = codestr.substring(0,codestr.lastIndexOf(";"));//去掉最后的;字符
       }
       if(valuestr.lastIndexOf(";")!=-1){//拼最后一个value时,valuestr字符串最后一个字符为;
           valuestr = valuestr.substring(0,valuestr.lastIndexOf(";"));//去掉最后的;字符
       }
       if(variablestr.lastIndexOf(";")!=-1){// 拼最后一个显示的变量code时,variablestr字符串最后一个字符为;
           variablestr = variablestr.substring(0,variablestr.lastIndexOf(";"));// 去掉最后的;字符
       }
       //alert(idstr);alert(codestr);alert(valuestr);
       document.mainForm.vid.value=idstr;//将idstr字符串赋给name为vid的表单隐藏域
       document.mainForm.vcode.value=codestr;//将codestr字符串赋给name为vcode的表单隐藏域
       document.mainForm.vvalue.value=valuestr;//将valuestr字符串赋给name为vvalue的表单隐藏域
       document.mainForm.variable.value=variablestr;//将valuestr字符串赋给name为vvalue的表单隐藏域
       var tag = "<%=tag%>";//获得修改或查看的标志
       var url;
       //alert(variablestr);
       if(tag=="up"){//up为修改;view为查看
          //默认表单提交到添加,如果接收到tag参数为up,更改表单提交地址为修改地址
          url="value.do?operate=doUpateValue&pid=<%=pid %>&mname="+m+"&vid="+idstr+"&vcode="+codestr+"&vvalue="+valuestr+"&variable="+variablestr;
       }else{
           url = "value.do?operate=doAddValue&pid=<%=pid %>&mname="+m+"&vid="+idstr+"&vcode="+codestr+"&vvalue="+valuestr+"&variable="+variablestr;
       }   
           $.post(url, function(data){
             var datas = data.split(',');
             if(datas[0]=="1"){
              //alert("保存成功!");
              var content = document.getElementById("content");
              content.innerHTML = "<div style='font-size:12px; text-align:center'>保存成功!</div><div style='font-size:12px; text-align:center; margin-top:10px;'><input type='button' value='确定' onclick='closeWindow()' style='width:60px;padding-top:5px;padding-bottom:3px;' />";
             }else{
              //alert("保存失败!");
              content.innerHTML = "<div style='font-size:12px; text-align:center'>保存失败!</div><div style='font-size:12px; text-align:center; margin-top:10px;'><input type='button' value='确定' onclick='closeWindow()' style='width:60px;padding-top:5px;padding-bottom:3px;'/></div>";
             }
             showDiv(datas[1]);
           },"html");
       }else{
        alert("登陆超时,请重新登录!");
        window.navigate("login.jsp");  
        }
       //document.mainForm.submit();//提交表单
    }
      

  3.   

    saveParts,虽然是按照页面的元素地类型分别取值的,但是太复杂,而且不可扩展。
    这个功能,分开写,分别保存元素值,这样就比较清楚了