【原創】利用Javascript實現動態插入行

來源:互聯網
上載者:User

 出處:http://blog.csdn.net/caoxicao
 作者:草惜草
 轉載請註明出處

昨天插入的時候用 <td id="tdtr1"></td>插入成功,今天卻不行了,總是提示“目標對象無效”,不解!

最後改成<div id="tdtr1"></div>居然成功!!!

function InsertNewLine(Id)
{

var Maxline=window.form1.Maxline.value;
var obj=eval("line"+Id);
var objDiv=eval("tdtr"+Id);
var MyLine
var re0;
re0=/(but_display|LineSeq|TransferID|TransferWhse|Consignee|Vendor|pickVendor|AllocateQty|AllocateType)(/()?(')?[1-9][0-9]?(')?(/))?/g;
var re1;
re1=/>[1-9][0-9]?</;
var modifiedHTML;

modifiedHTML=obj.innerHTML;
modifiedHTML=modifiedHTML.replace(re0,"$1"+"$2"+"$3"+String(Maxline)+"$4"+"$5");
modifiedHTML=modifiedHTML.replace(re1,"><");

var addHTML;
addHTML = "<table width=/"100%/" id=line"+String(Maxline)+" style=/"DISPLAY: block/" border=/"0/" cellspacing=/"1/" cellpadding=/"0/" align=/"center/" bgcolor=/"#decfa8/">";
addHTML = addHTML + modifiedHTML;
addHTML = addHTML + "</table>";

objDiv.insertAdjacentHTML("beforeEnd",addHTML);

eval("document.all('LineSeq" + Maxline+"').value =String(Maxline)"); 
eval("document.all('TransferID" + Maxline+"').value =''");
eval("document.all('TransferWhse" + Maxline+"').value =''");
eval("document.all('Consignee" + Maxline+"').value =''");
eval("document.all('Vendor" + Maxline+"').value =''");
eval("document.all('Vendor" + Maxline+"name').value =''");
eval("document.all('pickVendor" + Maxline+"').value =''");
eval("document.all('AllocateQty" + Maxline+"').value =''");
window.form1.Maxline.value = parseInt(Maxline)+1;
MyLine = parseInt(Maxline);

====================

  <div id="tdtr1"> 
  <table width="100%"  id=line1 style="DISPLAY: block" border="0" cellspacing="1" cellpadding="0" align="center" bgcolor=#decfa8>
 ... ...
  </div>
居然成功!不解!

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.