The method of using JavaScript background code to operate html table is javascripttable.

Source: Internet
Author: User

The method of using JavaScript background code to operate html table is javascripttable.

Var rowNum = 0, fileNum = 0; // row number and column number
Var oNewRow; // defines the inserted row object.
Var oNewCell1, oNewCell2; // defines the insert column object
Var fileNum = 1;

Function addFileToTable (strFile)
{
FileNum + = 1;
RowNum = document. getElementById ("NewFileList"). rows. length;
ONewRow = document. getElementById ("NewFileList"). insertRow (rowNum );
ONewRow. id = "clientRow _" + fileNum;

// Add the first column
ONewCell1 = document. getElementById ("NewFileList"). rows [rowNum]. insertCell (0 );
ONewCell1.innerHTML = "<input type = 'text' readonly = 'readonly' style = 'border: 0px; width: 100px; 'value = '" + getFileName (strFile) + "'/> ";

// Add the second column
ONewCell2 = document. getElementById ("NewFileList"). rows [rowNum]. insertCell (1 );
ONewCell2.innerHTML = "<span name =" + fileNum + "style = 'cursor: hand; color: Red; text-decoration: none; font-family: @ HGP ????? E; 'onclick = 'delclientrow (this); '> X </span> ";
}

 

 

How to operate html table using ASP. NET background code

Example 1: This method reads all the files in the folder "strFilePath" on the server and displays them in the TABLE with the ID "OldFileList" on the page. Note, the "runat = server" of this TABLE ".
Public void ShowFilesIn (string strFilePath)
{
OldFileList. Rows. Clear ();
String [] strFileNames = GetFilesInServer (strFilePath );
For (int I = 0; I <strFileNames. Length; I ++)
{
HtmlTableRow newRow = new HtmlTableRow ();
NewRow. ID = "serverRow _" + I;
HtmlTableCell cell1 = new HtmlTableCell ();
HtmlTableCell cell2 = new HtmlTableCell ();

Cell1.InnerHtml = "<input type = 'text' readonly = 'readonly' style = 'border: 0px; width: 90px; 'value = '"+ strFileNames [I] +"'/> ";
Cell2.InnerHtml = "<span name =" + strFileNames [I] + "style = 'cursor: hand; color: Red; text-decoration: none; font-family: @ HGP ????? E; 'onclick = 'delserverrow (this); '> X </span> ";
NewRow. Cells. Add (cell1 );
NewRow. Cells. Add (cell2 );
OldFileList. Rows. Add (newRow );
}
}


How to operate tables in html using javascript

Give td an ID
In JavaScript
Var tds = document. getElementById ("td ID ");
Tds. innerHTML = "data to be added ";
(InnerHTML attributes support tags)

Question about Html code output by javascript

<Body>
<Table width = "327" height = "176" border = "1">
<Tr>
<Td> </td>
<Td> <span id = "s_a"> </span> </td>
<Td> </td>
<Td> </td>
<Td> </td>
</Tr>
<Tr>
<Td> </td>
<Td> <span id = "s_ B"> </span> </td>
<Td> </td>
<Td> </td>
<Td> </td>
</Tr>
<Tr>
<Td> </td>
<Td> </td>
<Td> </td>
<Td> </td>
<Td> <span id = "s_c"> </span> </td>
</Tr>
</Table>
<Script>
// Put <span id = "s_ B"> </span> wherever you want. The value of id must be consistent with that of document. getElementById ("s_a ").
Var a = "This is the first ";
Var B = "This is B ";
Var c = "this is the c ";
Document. getElementById ("s_a"). innerHTML =;
Document. getElementById ("s_ B"). innerHTML =;
Document. getElementById ("s_c"). innerHTML =;
</Script>
</Body>

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.