Power Project 17--Data dictionary home JS add and delete tables

Source: Internet
Author: User

Knowledge Point:jquery is a library of JavaScript functions.

JS Code:

function InsertRows () {//Get Table Object    varTB1 = $ ("#dictTbl"); varTemprow = $ ("#dictTbl TR"). Size ();//get the number of rows in a table    var$tdNum = $ ("<td align= ' center ' ></td>");        $tdNum. HTML (temprow); var$tdName = $ ("<td align= ' center ' ></td>"); $tdName. HTML ("<input name=\ "itemname\" type=\ "text\" id=\ ""+temprow+"\ "size=\" 45\ "maxlength=25>"); var$tdDel = $ ("<td align= ' center ' ></td>"); $tdDel. HTML ("<a href= ' Javascript:deltablerow (\ ""+temprow+"\ ") ' ></a>"); //Create a TR and place 3 TD into TR    var$TR = $ ("<tr></tr>");    $tr. Append ($tdNum);    $tr. Append ($tdName);    $tr. Append ($tdDel); //Add the new TR at the end of the tabletb1.append ($TR);} 

Delete Change line number:

function Deltablerow (rowNum) {//Change line numbers and deleted line numbers   varTB1 = $ ("#dictTbl"); varTemprow = $ ("#dictTbl TR"). Size ();//get the number of rows in a table   if(Temprow >rowNum) {           //gets the object specified by the ID of the deleted row, for example: <input name=\ "itemname\" type=\ "text\" id=\ "+temprow+" \ "size=\" 45\ "maxlength=25>$("#"+rowNum). Parent (), parent (). remove (); //add 1 to look for the next ID to move the format of the following TR up       for(I= (parseint (rowNum) +1); i<temprow;i++){          //assigns the value of the i-1 to the number$("#"+i). Parent (). Prev (). HTML (i-1); //assign a value of i-1 to the deletion of a hyperlink$("#"+i). Parent (). Next (). HTML ("<a href= ' Javascript:deltablerow (\ ""+ (I-1)+"\ ") ' ></a>");//          //assigns the value of I-1 to the ID of the text box, which is used to delete$("#"+i). attr ("ID", (I-1));//set the ID to i-1      }   }} 

JSP Code:

<table cellspacing="0"cellpadding="1"rules=" All"Bordercolor="Gray"Border="1"Id="Dicttbl"style="Border-right:gray 1px solid; Border-top:gray 1px solid; Border-left:gray 1px solid; width:100%; Word-break:break-all; Border-bottom:gray 1px solid; Border-collapse:collapse; Background-color: #f5fafe; Word-wrap:break-word"> <tr style="Font-weight:bold; font-size:12pt; height:25px; Background-color: #afd1f3"> &LT;TDclass="ta_01"align="Center"Width="20%"height= ABackground="${pagecontext.request.contextpath}/images/tablehead.jpg"> Number </td> &LT;TDclass="ta_01"align="Center"Width="60%"height= ABackground="${pagecontext.request.contextpath}/images/tablehead.jpg"> Name </td> <tdclass="ta_01"align="Center"Width="20%"height= ABackground="${pagecontext.request.contextpath}/images/tablehead.jpg"> Delete </td> </tr> <tr> <tdclass="ta_01"align="Center"Width="20%">1</td> &LT;TDclass="ta_01"align="Center"Width="60%"> <input name="ItemName"Type="text"Size=" $"Maxlength=" -"></td> &LT;TDclass="ta_01"align="Center"Width="20%"></td> </tr> </table>

When using the <table> tag implementation table to add rows and delete rows, the background gets the value of the page fill, this is a string type of array object, you can use the way to iterate over the array, save the data.

Power Project 17--Data dictionary home JS add and delete tables

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.