知道了,你在查找length之前,应该先判断一下这个对象是否存在,如果不存在就不执行下面的程序就可以了。

解决方案 »

  1.   

    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>JK:支持民族工业,尽量少买X货</title><style>
    TD,INPUT{ font-size:12; }
    </style>
    </head><body bgcolor=EEEEEE>
    <form name="frm" action="about:结果页面" method=post >
    <h4 align=center>代码改自:JK的动态明细示例</h4><table align="center" bordercolor=cccccc border=1  width=100% >
    <tr>
    <td width=500>
    </td>
    <td align=right>
          <input type="button"  value="增加" class="bottom" onclick="addDetailProcess();">&nbsp;                 
          <input type="button"  value="删除" class="bottom" onclick="delDetailProcess();">&nbsp;                 
          <input type="button"  value="完成" class="bottom" onclick="submitProcess();">
          
    </td>
    </tr>
    </table>
    <div width=100% id=thedetailtableDIV>
    <table align="center" bordercolor=cccccc border=1 width=100% >
      <tr bgcolor=eeeeee id="trDetailTitles"> 
        <td ><input type=checkbox onclick="selectallcheckbox(this)"></td>
        <td >明细ID*</td>
        <td >明细NAME</td>
      </tr>
      <tbody id="tbDetailUsed" >
    <tr height=0 ><td colspan=100 height=0 > 合计</td></tr>
      </tbody> </table>
    </div>
    </form><!--复制的内容-->
    <table id="tbDetailPrepare" style="display:none">
    <tr>
    <td ><input type="checkbox" name="record_select" ></td>
    <td ><select name=Hotel_Id_Type size=4  style = 'width:150;' onChange='fill(this)' >
    <option value='' selected >全部</option><OPTION VALUE=31601023>青岛远洋大酒店</option>
    <OPTION VALUE=31601031>青岛远洋大酒店-梅特勒</option>
    </select></td>
    <td ><select name=Room_Type_Id multiple style="width:300"><option value=''>全部</option></select></td>
    </tr>
    </table>
    <input name="theHistoryRecord" type=hidden value="">
    </body></html><SCRIPT language=javascript>
    var arrHotelRoomTypeNum=new Array(); 
    arrHotelRoomTypeNum[0]=new Array(2); 
    arrHotelRoomTypeNum[0][0]='31601023';
    arrHotelRoomTypeNum[0][1]='1017';
    arrHotelRoomTypeNum[0][2]='梅特勒-标间';
    arrHotelRoomTypeNum[1]=new Array(2); 
    arrHotelRoomTypeNum[1][0]='31601023';
    arrHotelRoomTypeNum[1][1]='1018';
    arrHotelRoomTypeNum[1][2]='asia-街景标准间';
    arrHotelRoomTypeNum[2]=new Array(2); 
    arrHotelRoomTypeNum[2][0]='31601023';
    arrHotelRoomTypeNum[2][1]='1019';
    arrHotelRoomTypeNum[2][2]='asia-海景标准间';
    arrHotelRoomTypeNum[3]=new Array(2); 
    arrHotelRoomTypeNum[3][0]='31601023';
    arrHotelRoomTypeNum[3][1]='1020';
    arrHotelRoomTypeNum[3][2]='asia-标准大床房';
    arrHotelRoomTypeNum[4]=new Array(2); 
    arrHotelRoomTypeNum[4][0]='31601023';
    arrHotelRoomTypeNum[4][1]='1021';
    arrHotelRoomTypeNum[4][2]='asia-普通套房';
    arrHotelRoomTypeNum[5]=new Array(2); 
    arrHotelRoomTypeNum[5][0]='31601031';
    arrHotelRoomTypeNum[5][1]='1017';
    arrHotelRoomTypeNum[5][2]='梅特勒-街景标准间(淡季)';
    arrHotelRoomTypeNum[6]=new Array(2); 
    arrHotelRoomTypeNum[6][0]='31601031';
    arrHotelRoomTypeNum[6][1]='1018';
    arrHotelRoomTypeNum[6][2]='梅特勒-街景标准间(平季)';
    </SCRIPT><script language=javascript> window.onload = historyOncemore;
    window.onbeforeunload = fixHistory; function fixHistory() //记住历史
    {
    document.all("theHistoryRecord").value=document.all("thedetailtableDIV").innerHTML.replace(/\n/g,"");
    } function historyOncemore() //恢复历史
    {
    if (document.all("theHistoryRecord").value!="")
    {document.all("thedetailtableDIV").innerHTML=document.all("theHistoryRecord").value;
    }
    } function selectallcheckbox(obj) //全选或全不选
    {
    var tureorfalse=obj.checked;
    var theDetail=tbDetailUsed.rows;
    for(var i=0;i<theDetail.length-1;i++)
    {
    theDetail[i].all("record_select").checked=tureorfalse;
    }
    }


    function addDetailProcess(afterRowIndex) //增加明细
    {
    var alltbDetailUsed= document.all("tbDetailUsed").rows;
    var theFirstSelectedDetail;
    if (afterRowIndex==null)
    {
      theFirstSelectedDetail=alltbDetailUsed.length-2;
    }
    else theFirstSelectedDetail=afterRowIndex;
    var newRow = document.all("tbDetailPrepare").rows[0].cloneNode(true);
    var desRow = alltbDetailUsed[theFirstSelectedDetail+1];
    desRow.parentElement.insertBefore(newRow,desRow ); }

    function delDetailProcess() //删除明细
    {
    var alltbDetailUsed= document.all("tbDetailUsed").rows;
    if (confirm("确定选择正确并且要将这些明细删除")==false) return false;
    for(var i=0;i<alltbDetailUsed.length-1;i++)
    {
    if (alltbDetailUsed[i].all("record_select").checked==true)
    {
    document.all("tbDetailUsed").deleteRow(i);
    i=i-1;
    }
    }
    } function submitProcess()
    {
          document.frm.submit();
    }function fill(obj)
    { var theNextSelect=obj.parentElement.parentElement.all.Room_Type_Id;
    theNextSelect.length=1;
    for (i = 0; i < arrHotelRoomTypeNum.length; i++) 
    {
    if (arrHotelRoomTypeNum[i][0]==obj.value)
    theNextSelect.add(new Option(arrHotelRoomTypeNum[i][2], arrHotelRoomTypeNum[i][1]));
    }}</script>