[Original] use JavaScript to dynamically Insert rows

Source: Internet
Author: User

Source: http://blog.csdn.net/caoxicao
Author: caoxi grass
Reprinted please indicate the source

When I inserted the object yesterday, I used <TD id = "tdtr1"> </TD> to insert the object successfully. Today, the object cannot be inserted. The system always prompts "the target object is invalid!

Finally, it was successfully changed to <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>
Actually succeeded! Puzzled!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.