posts - 9,  comments - 11,  trackbacks - 0
          http://hi.baidu.com/supersolon/blog/item/c07bca86cf9307b26d8119e6.html JS動態對表單進行添加和修改

          http://hi.baidu.com/supersolon/blog/item/7a52c6562cebb9030df3e3e5.html JS實現區域打印,去頁眉頁腳
          Title

          <%@ page language="java" contentType="text/html;charset=GBK"
          import="java.util.Date"%>


          <%@ taglib uri="<%@ taglib uri="<%@ taglib uri="<%@ taglib uri="

          <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
          <%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt"%>

          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
          <html:html>
          <head>
          <title>市局辦公用品-新個人申領</title>
          <fmt:setBundle basename="MyResource" scope="session" />
          <meta http-equiv="pragma" content="no-cache">
          <meta http-equiv="cache-control" content="no-cache">
          <meta http-equiv="expires" content="0">
          <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
          <meta http-equiv="description" content="This is my page">
          <link href="<fmt:message key='StylePath' />style.css" rel="stylesheet"
             type="text/css">
          <script type="text/javascript"
             src="<fmt:message key='JavaScriptPath' />common.js"></script>
          <script language="javascript"
             src="<fmt:message key='JavaScriptPath' />meizzDate.js"></script>
          <script language="JavaScript"
             src="<fmt:message key='JavaScriptPath' />GetDate.js"></script>
          <script language="JavaScript" src="common/js/dojo/dojo.js"></script>
          <script type='text/javascript'
             src='<%=request.getContextPath()%>/dwr/interface/OfficeSuppliesLogic.js'></script>
          <script type='text/javascript'
             src='<%=request.getContextPath()%>/dwr/engine.js'></script>
          <script language="javascript"
             src="<c:out value="${pageContext.request.contextPath}"/>/common/js/js_select.js"></script>
          <script language="javascript">
          //dwr.engine.setAsync(false);
          var csbh="<c:out value="${sessionScope.currentUserData.csbh}"/>";
          var goodsindex=0;
             function submitButton(obj)
          {
          if(obj.value==""){
          return;
          }
          OfficeSuppliesLogic.queryGoods(obj.value,csbh,setGoods);
          }
          function handleSetSelectIndexAsValue(destSideId,value){
                 var destSide=document.getElementById(destSideId);
              if(destSide==null)return;
              for(var j=0;j<destSide.options.length; j++){
             if(destSide.options[j].value==value){
                 destSide.selectedIndex=j;
                break;
              } 
            }
           
           }


          function setGoods(data){
             handleRemoveAll("goods");

          if(data==null ||data=='null'){return;}

          for(var i=0;i<data.length;i++){
          var officeSuppliesModel=data[i];

          if(officeSuppliesModel==null ||officeSuppliesModel=='null' ){continue;}

          var goodsId=officeSuppliesModel.id;
          var goodsName=officeSuppliesModel.name;
          var goodsUnit=officeSuppliesModel.unit;
          handleAdd("goods",goodsId+"|"+goodsUnit,goodsName);
               }
             }

          function backClick()
          {
              document.forms[0].method.value="queryExamePersonSuppliesByUser";
             return true;
          }
          function saveClick()
          {
             document.forms[0].typeName.value=document.forms[0].typeId.options[document.forms[0].typeId.selectedIndex].text;
             document.forms[0].goodsName.value=document.forms[0].goods.options[document.forms[0].goods.selectedIndex].text;
             count=document.forms[0].goodsName.value;
             if(count==null || count.length<=0)
             {
              alert('物品名稱不能為空!');
              document.forms[0].goodsName.value='';
              return false;
             }
             count=document.forms[0].applyCount.value;
             if(count==null || count<='0')
             {
              alert('數量不能小(等)于零或為空!');
              document.forms[0].applyCount.value='';
              return false;
             }
            
             return true;
          }
          function startClick()
          {
              var checknum=0;
              var checkBoxs=document.getElementsByName("applyid");
              for(var i=0;i<checkBoxs.length;i++){
                  
                     if(checkBoxs[i].checked){
               
                       checknum=checknum+1;
                     }
                }
               
                if(checknum==0){
                 alert("可提交的申請項為空,請選擇申請項后進行提交!");
                 return false;
                }
             document.forms[0].method.value="createPersonSuppliesDraw";

             return true;
          }
              function goodChange()
              {
                  var val=document.forms[0].goods.options[document.forms[0].goods.selectedIndex].value;
             var arry=val.split('|');
             try{
                  document.forms[0].unit.value=arry[1];
                   document.forms[0].goodsId.value=arry[0];
               
              if(document.getElementById('display').hasChildNodes())
                   {
                       document.getElementById('display').removeChild(document.getElementById('display').childNodes[0]);
                   }
                //   document.getElementById('display').removeChild(document.getElementById('display'));
                      document.getElementById('display').appendChild(document.createTextNode(arry[1]));
                
             }catch(e)
             {}
              }

          function addGoods(){
          if(!saveClick()){
          return;
          }
               var opertype=document.forms[0].opertype.value;
          var typeName=document.forms[0].typeId.options[document.forms[0].typeId.selectedIndex].text;
               var typeId=document.forms[0].typeId.options[document.forms[0].typeId.selectedIndex].value;
               var goodsName=document.forms[0].goods.options[document.forms[0].goods.selectedIndex].text;
             var goods_id="-1";
                var unit="";
             var val=document.forms[0].goods.options[document.forms[0].goods.selectedIndex].value;

             var arry=val.split('|');
             try{
                   unit=arry[1];
                   goods_id=arry[0];
                     }catch(e)
             {}

               var applyCount=document.forms[0].applyCount.value;
              

          var table=document.getElementById("bgyptable");
               if(opertype==""){
             var newTr = table.insertRow(table.rows.length-1);

                               newTr.id=goodsindex;
                               var newTd0 = newTr.insertCell();
                newTd0.className="table2_td";
                               newTd0.innerHTML=typeName+"<input type=hidden value='"+typeName+"' name='typeName_"+goodsindex+"'>"
                                       +"<input type=hidden value='"+typeId+"' name='typeId_"+goodsindex+"'>";
                               var newTd1 = newTr.insertCell();
                 newTd1.className="table2_td";
                               newTd1.innerHTML=goodsName+"<input type=hidden value='"+goodsName+"' name='goodsName_"+goodsindex+"'>"
                                       +"<input type=hidden value='"+goods_id+"' name='goods_id_"+goodsindex+"'>"
                                       +"<input type=hidden value='"+unit+"' name='unit_"+goodsindex+"'>";  
                   
                 var newTd3 = newTr.insertCell();
                  newTd3.className="table2_td";
                               newTd3.innerHTML=applyCount+unit+"<input type=hidden value='"+applyCount+"' name='applyCount_"+goodsindex+"'>";   
               
                var newTd6 = newTr.insertCell();
                newTd6.className="table2_td";
                               newTd6.innerHTML="<span onclick='javascript:setModify(this.parentElement.parentElement)'>修改</span><input type=checkbox value='"+goodsindex+"' name='applyid' checked='true'>";
                      goodsindex=goodsindex+1;
          }else{

              for(var i=0;i<table.rows.length-1;i++){
               obj=table.rows[i];
             
               if(obj.cells.length<3||obj.cells[3].getElementsByTagName("input").length==0||obj.cells[3].getElementsByTagName("input")[0].type!="checkbox"){
               continue;
               }
              var rowid=obj.cells[3].getElementsByTagName("input")[0].value;
              if(rowid==opertype){
             obj.cells[0].innerHTML=typeName+"<input type=hidden value='"+typeName+"' name='typeName_"+rowid+"'>"
                                       +"<input type=hidden value='"+typeId+"' name='typeId_"+rowid+"'>";
             obj.cells[1].innerHTML=goodsName+"<input type=hidden value='"+goodsName+"' name='goodsName_"+rowid+"'>"
                                       +"<input type=hidden value='"+goods_id+"' name='goods_id_"+rowid+"'>"
                                       +"<input type=hidden value='"+unit+"' name='unit_"+rowid+"'>";  
               
                obj.cells[2].innerHTML=applyCount+unit+"<input type=hidden value='"+applyCount+"' name='applyCount_"+rowid+"'>";   
               
              
               document.forms[0].opertype.value="";
               document.getElementById("okbutton").value="增加到申請列表";

              }   
             
              }

              }

              document.forms[0].applyCount.value="";

             // document.forms[0].guige.value="";
          //document.forms[0].typeId.selectedIndex=0;
          //document.forms[0].goods.selectedIndex=0;

          }

          function setModify(obj){
             var id=obj.cells[3].getElementsByTagName("input")[0].value;  
              document.forms[0].opertype.value=id;

               document.forms[0].applyCount.value=obj.cells[2].getElementsByTagName("input")[0].value;
            
               //document.forms[0].guige.value=obj.cells[3].getElementsByTagName("input")[0].value;
               handleSetSelectIndexAsValue("typeId",obj.cells[0].getElementsByTagName("input")[0].value);
          submitButton(document.getElementById("typeId"));
          handleSetSelectIndexAsValue("goods",obj.cells[1].getElementsByTagName("input")[1].value+"|"+obj.cells[1].getElementsByTagName("input")[2].value);
          document.getElementById("okbutton").value="確定";
          }
             
          </script>
          </head>
          <body>
          <!--------------以下Table為路徑-------->
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
             <tr>
              <td height="30" class="place">
               <img src="<fmt:message key='CommonImagePath' />place_btn.gif"
                width="12" height="11">
               當前位置:北京市藥監局 >> 輔助辦公 >> 辦公用品申請
              </td>
             </tr>
             <tr>
              <td height="10">
              </td>
             </tr>
          </table>
          <!--------------Table為路徑結束-------->


          <table width="95%" border="0" align="center" cellpadding="0"
             cellspacing="0" class="table1_border">
             <tr>
              <td class="table1_head_title">
               <img src="<fmt:message key='CommonImagePath' />table1_head_ico.gif"
                width="26" height="23" align="absmiddle">
               辦公用品領用登記
              </td>
             </tr>
             <tr>
              <td class="table1_head_line">
              </td>
             </tr>

             <script>
             var count=0;
             </script>

           

             <tr>
              <td align="center">

               <html:form action="/exameOfficeSupplies">

                <html:hidden property="method" value="createPersonSuppliesDraw" />
                <html:hidden property="applyUserId" />
                <html:hidden property="applyUserName" />
                <html:hidden property="applyDeptId" />
                <html:hidden property="applyDeptName" />
                <html:hidden property="goodsName" />
                <html:hidden property="typeName" />
                <html:hidden property="unit" />
                <html:hidden property="priceIsAdmin" />


                <input type="hidden" name="unit" />

                <input type="hidden" name="atid" />
                <input type="hidden" name="tid" />
                <input type="hidden" name="selPeoType" />

                <table id="bgyptable" align="center" width="90%" border="0"
                 align="center" cellpadding="0" cellspacing="1"
                 class="table2_border">

                 <tr>
                  <td class="table2_td_title" width="15%">
                   所屬類別
                  </td>
                  <td class="table2_td_title" width="15%">
                   名稱
                  </td>

                  <td class="table2_td_title" width="15%">
                   數量
                  </td>

                  <td class="table2_td_title" width="10%">
                   是否提交
                  </td>
                 </tr>


                 <tr>
                  <td class="table2_td">
                   <input id="opertype" name="opertype" type=hidden value="">
                   <select id="typeId" name="typeId" tmpid="2"
                    onchange="submitButton(this);">
                    <option />
                     <c:forEach items="${typeList}" var="OfficeSuppliesTypeModel">
                      <option
                       value="<c:out value="${OfficeSuppliesTypeModel.id}"/>"
                       <c:if test="${OfficeSuppliesTypeModel.id==typeId}">
                          selected
                         </c:if> />
                       <c:out value="${OfficeSuppliesTypeModel.sort}" />
                      </option>

                     </c:forEach>
                   </select>
                  </td>
                 
                  <td class="table2_td">

                   <INPUT type="hidden" name="goodsId_2">
                   <select id="goods" name="goods" onchange="goodChange(this);">
                    <option />
                     <c:forEach items="${goodsList}" var="OfficeSuppliesModel">
                      <option
                       value="<c:out value="${OfficeSuppliesModel.id}"/>|<c:out value="${OfficeSuppliesModel.unit}"/>"
                       <c:if test="${OfficeSuppliesModel.id==officeSuppliesDrawForm.goods_id}">
                        selected </c:if> />
                       <c:out value="${OfficeSuppliesModel.name}" />
                      </option>
                     </c:forEach>
                   </select>
                  </td>


                  <td class="table2_td">
                   <input type=text name="applyCount" size="6" maxlength="20" />

                  </td>


                  <td class="table2_td">
                   <input id="okbutton" type="button" value="增加到申請列表"
                    onclick="javascript:addGoods()">
                  </td>
                 </tr>
                </table>


                <table align="center" width="90%" border="0" align="center"
                 cellpadding="0" cellspacing="1" class="table2_border">

                 <tr>
                  <td align="center" class="table2_btn" colspan="6">
                   <input type="image"
                    src="<fmt:message key='CommonImagePath' />btnSubmit.gif"
                    onclick="return startClick()">
                   &nbsp;

                   <input type="image"
                    src="<fmt:message key='CommonImagePath' />btnBack.gif"
                    onclick="return backClick()">


                  </td>
                 </tr>
                </table>
                <%@include file="../common/getDisplayParams1.jsp"%>
                <!-- 維護視圖狀態的隱藏域 -->
                <!-- 維護視圖狀態的隱藏域 -->
               </html:form>

              </td>
             </tr>
          </table>

           

          </body>

          </html:html>

          posted on 2011-07-25 11:23 Mon$ter! 閱讀(3430) 評論(2)  編輯  收藏


          FeedBack:
          # re: JS動態對表單進行添加和修改
          2014-11-13 12:00 | 158
          4  回復  更多評論
            
          # re: JS動態對表單進行添加和修改
          2014-11-13 12:01 | 158
          今天是個好日子  回復  更多評論
            

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2014年11月>
          2627282930311
          2345678
          9101112131415
          16171819202122
          23242526272829
          30123456

          常用鏈接

          留言簿

          隨筆檔案(11)

          文章分類

          最新隨筆

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 台东市| 名山县| 丰顺县| 杭州市| 公安县| 连江县| 东乡族自治县| 黎平县| 当涂县| 涟源市| 陵水| 阿克陶县| 东台市| 寿宁县| 丽水市| 恩施市| 宣汉县| 溆浦县| 信丰县| 仪征市| 鲜城| 祥云县| 原阳县| 淅川县| 永吉县| 铜梁县| 永安市| 迭部县| 蒙城县| 江津市| 浮山县| 南充市| 博野县| 东至县| 江陵县| 电白县| 和政县| 拜城县| 溧水县| 璧山县| 云浮市|