JS allows you to add, modify, and delete dynamic tables (recommended) and js tables.

Source: Internet
Author: User

JS allows you to add, modify, and delete dynamic tables (recommended) and js tables.

1. configure a table framework on the page.

<Tr> <td> new parameter: </td> <td class = "pn-fcontent"> <input type = "button" value = "select" onclick = "openAppParamsPage (); "/> </td> <td> parameter list: </td> <td class = "pn-fcontent"> <input type = "hidden" id = "paramslist" name = "paramslist" style = "width: 190% "height =" 500 "/> </td> </tr> <table id =" tab "width =" 100% "cellspacing =" 1 "cellpadding =" 0 "border =" 0 "style =" "class =" pn-ltable "> <tr> <td height =" 20 "valign =" top "align =" center "> parameter Name: </td> <td height = "20" valign = "top" align = "center"> parameter encoding: </td> <td height = "20" valign = "top" align = "center"> parameter values: </td> <td id = "pos_1" height = "20"> operation </td> </tr> <tbody id = "sortList"> </tbody> </ table> </tr> <td align = "center" colspan = "4"> <input type = "submit" class = "btn" value = "save" onclick = "setParamslist (); "/> <input type =" button "class =" btn "value =" return "/> </td> </tr>

2. Related JS Functions

Function setParamslist () {var tab = document. getElementById ("tab"); // table row var rows = tab. rows. length; // Number of table columns var cells = tab. rows. item (0 ). cells. length; // alert ("number of rows" + rows + "Number of columns" + cells); var rowData = ""; for (var I = 1; I <rows; I ++) {var cellsData = new Array (); for (var j = 0; j <cells-1; j ++) {cellsData. push (tab. rows [I]. cells [j]. innerText);} rowData = rowData + "|" + cellsData;} document. getElementById ("Paramslist"). value = rowData;} // open the related newly added Application parameter interface function openAppParamsPage () {var param = new Object (); // This parameter must be passed. Param. win = window; param. id = 100; param. name = "test"; param. birthday = new Date (); var result = window. showModalDialog ("addParamsItem", "dialogWidth: 500px; dialogHeight: 600px; dialogLeft: 200px; dialogTop = 200px"); // var temp = document. getElementById ("paramslist "). value; // document. getElementById ("paramslist "). value = temp + result; addSort (result);} // adds the application Parameter function addSort (data) {var name = Data; if (name = "" | name = undefined) {return;} console. log (data); var params = data. split (","); var paramName = params [0]; var paramCode = params [1]; var paramValue = params [2]; var row = document. createElement ("tr"); row. setAttribute ("id", paramCode); var cell = document. createElement ("td"); cell. appendChild (document. createTextNode (paramName); row. appendChild (cell); cell = document. createEle Ment ("td"); cell. appendChild (document. createTextNode (paramCode); row. appendChild (cell); cell = document. createElement ("td"); cell. appendChild (document. createTextNode (paramValue); row. appendChild (cell); var deleteButton = document. createElement ("input"); deleteButton. setAttribute ("type", "button"); deleteButton. setAttribute ("value", "delete"); deleteButton. onclick = function () {deleteSort (paramCode) ;}; Cell = document. createElement ("td"); cell. appendChild (deleteButton); row. appendChild (cell); document. getElementById ("sortList "). appendChild (row);} // Delete the application Parameter function deleteSort (id) {if (id! = Null) {var rowToDelete = document. getElementById (id); var sortList = document. getElementById ("sortList"); sortList. removeChild (rowToDelete );}}

Additional table modification functions

// Function updateSort (id) {if (id! = Null) {var row = document. getElementById (id); // alert ("row is" + row. cells [0]. innerHTML); var id = row. cells [0]. innerHTML; var paramName = row. cells [1]. innerHTML; var paramCode = row. cells [2]. innerHTML; var paramValue = row. cells [3]. innerHTML; var param = new Object (); // This parameter must be passed. Param. win = window; param. id = 100; param. name = "test"; param. birthday = new Date (); var result = window. showModalDialog (baseUrl + "app/updateParamsItem? Id = "+ id +" Your mName = "+ paramName +" Your mCode = "+ paramCode +" Your mValue = "+ paramValue," dialogWidth: 500px; dialogHeight: 600px; dialogLeft: 200px; dialogTop = 200px "); var arr = result. split (","); row. cells [0]. innerHTML = arr [0]; row. cells [1]. innerHTML = arr [1]; row. cells [2]. innerHTML = arr [2]; row. cells [3]. innerHTML = arr [3] ;}}

3. On the pop-up page, add or modify parameters and write back relevant data.

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

The above section describes how to add, modify, and delete dynamic tables in Javascript. I hope this will be helpful to you, if you have any questions, please leave a message and the editor will reply to you in time. Thank you very much for your support for the help House website!

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.