Precautions for nested tbody elements _ javascript skills

Source: Internet
Author: User
Note that the tbody element supports nesting function addMessage (messageID, userName, userCreateDate, articleCount, subject, body, creationDate, modifiedDate)
{
Var br;
Var row = document. createElement ("tr ");
Var cell = document. createElement ("td ");

Var cellTr = document. createElement ("tr ");
Var cellTd = document. createElement ("td ");
CellTd. appendChild (document. createTextNode ("userName:" + userName ));
CellTr. appendChild (cellTd );
Cell. appendChild (cellTr );
CellTd = document. createElement ("td ");
CellTd. appendChild (document. createTextNode ("created at: + userCreateDate "));
CellTr. appendChild (cellTd );
Cell. appendChild (cellTr );
CellTd = document. createElement ("td ");
CellTd. appendChild (document. createTextNode ("published:" + articleCount ));
CellTr. appendChild (cellTd );
Cell. appendChild (cellTr );
Row. appendChild (cell );

Cell = document. createElement ("td ");
CellTr = document. createElement ("tr ");
CellTd = document. createElement ("td ");
CellTd. appendChild (document. createTextNode ("published on:" + creationDate + "" + "modified on:" + modifiedDate ));
CellTr. appendChild (cellTd );
Cell. appendChild (cellTr );
CellTr = document. createElement ("tr ");
CellTd = document. createElement ("td ");
CellTd. appendChild (document. createTextNode (subject ));
Br = document. createElement ("br ");
CellTd. appendChild (br );
CellTd. appendChild (document. createTextNode (body ));
CellTr. appendChild (cellTd );
Cell. appendChild (cellTr );
Row. appendChild (cell );

Document. getElementById ("messageList"). appendChild (row );
}
The above code shows "accidentally calling methods or attribute access" in ie. The error points to the last sentence.

Rating:
Your code is not elegant ~ No reusability ~ Performance base ~ ,
Suggestion:
1> function encapsulation is used for reuse.
2> the internal nesting of the table adopts the following format:













... ... ...



Dynamically generate a table using an internal to external addition scheme. Use document. createTextNode as little as possible, with low performance.
3> if your table is not executed during page loading, we recommend that you
Related Article

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.