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="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles"%>

<%@ 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! 阅读(3408) 评论(2)  编辑  收藏


FeedBack:
# re: JS动态对表单进行添加和修改
2014-11-13 12:00 | 158
4  回复  更多评论
  
# re: JS动态对表单进行添加和修改
2014-11-13 12:01 | 158
今天是个好日子  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航:
 
<2011年7月>
262728293012
3456789
10111213141516
17181920212223
24252627282930
31123456

常用链接

留言簿

随笔档案(11)

文章分类

最新随笔

搜索

  •  

最新评论

阅读排行榜

评论排行榜