JS dynamically creates tables, Tr, Td, and assigns values

Source: Internet
Author: User
Modify the fruit Database: the topic list is required to change the online data query mode as the result type changes. In the results type drop-down box, add the change () event to trigger Dwr and query the topic set & mdash; the summary code of dynamic Table creation/editing is as follows: Jsp page [javascript] // dynamic topic data acquisition... modify the SyntaxHighlig fruit database:
The topic list must change with the result type.
After you query data on the Internet, start the operation. In the result type drop-down box, add the change () event to trigger Dwr and query the topic set-dynamically create/edit a Table.
The Code is as follows:
 
Jsp page
[Javascript]
// Obtain topic data dynamically
Function getzts (){
ParentId = document. getElementById ("bselect1"). value;
If (parentId! = ""){
DwrMethod. getZtList (parentId, callback5 );
} Else {
// Clear the data of the topic Table
Var t = document. getElementById ("zhutiTable"); // get Table
Var length = t. rows. length; // obtain the number of rows in the Table.
If (length! = 0) {// clear if there are rows
For (var I = length-1; I> = 0; I --)
{
T. deleteRow (I );
}
}
Var r = t. insertRow ();
Var c = r. insertCell ();
C. innerHTML = "No topic list ";
Document. getElementById ('zhutitable'). appendChild (t );
}
}
Function callback5 (provinces ){
Var t = document. getElementById ("zhutiTable"); // get Table
Var length = t. rows. length; // obtain the number of rows in the Table.
If (length! = 0) {// clear if there are rows
For (var I = length-1; I> = 0; I --)
{
T. deleteRow (I );
}
}
If (provinces. length> 0 ){
For (var I = 0; I <provinces. length; I ++ ){
// Tr
If (I % 4 = 0 ){
Var r = t. insertRow (t. rows. length); // create a new row.
}
// Td
Var c = r. insertCell (); // create a new column
C. innerHTML =" "+ Provinces [I] [1];
}
} Else {
Var r = t. insertRow ();
Var c = r. insertCell ();
C. innerHTML = "No topic list ";
}
Document. getElementById ('zhutitable'). appendChild (t );
}
 
[Html]
 
Result type 
 
 

 
 
[Html]
 
Topic 
 




   
Note: select the result type first.
 
 
 

From the day of that year and month
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.