Example of dynamically adding table rows or columns using jquery

Source: Internet
Author: User


Share the Code!

Html

<div class= "table-responsive" id= "bk_table" style= "Display:none"; >
<table class= "Table Table-hover table-bordered" >
<thead>
<tr>
<th>
<div class= "Out" >
<b> Plate </b>
<em> Dimension </em>
</div>
</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>

JS operation is as follows:

Deletelie:function () {//delete a column
var index = $ (this). Parent (). index ();
for (var i = 0; I < $ (". Table tr"). Length; i++) {
$ ($ (". Table tr") [i]). Children (). EQ (index). Remove ();
}
if ($ (". Table tr"). Length = = 1 && $ (". Table tr"). EQ (0). Children (). length = = 1) {
$ ("#Bk_table"). Hide ();
$ (". Blankshow"). Show ();
}
},
Deleteoneline:function () {//delete row
$ (this). Parent (). Parent (). remove ();
if ($ (". Table tr"). Length = = 1 && $ (". Table tr"). EQ (0). Children (). length = = 1) {
$ ("#Bk_table"). Hide ();
$ (". Blankshow"). Show ();
}
},
Addonebk:function () {//Add a column
if ($ ("#Bk_table"). Is (": hidden")) {
$ ("#Bk_table"). Show ();
}
if ($ (". Blankshow"). Is (": visible")) {
$ (". Blankshow"). Hide ();
}
var Firstlie = ' <th class= "hovershow" ><span class= "Font_zs" style= "Display:none" > in Hong West Bank 3</span> ' +
' <input type= ' text "class=" Form-control getprevalue "placeholder=" fill in the plate name "/>" +
' <a class= ' glyphicon glyphicon-remove bkdelete delete_lie ' ></a></th> ';
$ (". Table>thead>tr"). EQ (0). append (Firstlie);
var Otherlie = ' <td><input type= ' text ' class= ' form-control ' value= ' ' placeholder= ' 1-5 number ' +
' onkeyup= ' if (isNaN (value) | | parsefloat (value) >5| | parsefloat (value) <1) execcommand (\ ' undo\ ') "' +
' Onafterpaste= ' if (isNaN (value) | | parsefloat (value) >5| | parsefloat (value) <1) execcommand (\ ' undo\ ') "/></td>";
$ (". Table>tbody>tr"). Append (Otherlie);
},
Addwd:function () {//Add one line
if ($ ("#Bk_table"). Is (": hidden")) {
$ ("#Bk_table"). Show ();
}
if ($ (". Blankshow"). Is (": visible")) {
$ (". Blankshow"). Hide ();
}
var wdhtml_1 = ' <tr> ' +
' <th scope= ' row ' class= ' hovershow ' > ' +
' <span class= ' Font_zs T1 ' style= ' Display:none ' > Dimension III </span> ' +
' <input type= ' text ' class= ' Form-control getprevalue ' placeholder= ' Fill in Dimension name '/> ' +
' <a class= ' glyphicon glyphicon-remove bkdelete deleteoneline ' ></a> ' +
' </th> ';
var wdhtml_2 = "";
var lielength = $ (". Table>thead>tr"). Children (). Length-1;
if (Lielength > 0) {
for (var i = 0; i < lielength; i++) {
wdhtml_2 = wdhtml_2 + ' <td><input type= "text" class= "Form-control" value= "" placeholder= "1-5 the number" onkeyup= "if ( isNaN (value) | | parsefloat (value) >5| | parsefloat (value) <1) execcommand (\ ' undo\ ') "onafterpaste=" if (isNaN (value) | | parsefloat (value) >5| | parsefloat (value) <1) execcommand (\ ' undo\ ') "/></td>";
}
}
var wdhtml_3 = ' </tr> ';
var allwd = wdhtml_1 + wdhtml_2 + wdhtml_3;
$ (". Table>tbody"). Append (ALLWD);
}
The above posted is part of the code, there are problems to communicate!

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.