简体   繁体   English

如何通过JQuery动态生成html中特定行表的列

[英]How to dynamically generate column of particular row of table in html through JQuery

I m stuck here so please help me out. 我被困在这里所以请帮助我。 I have a html table which look like this 我有一个看起来像这样的html表

ID | Name | DOB | Action|

And when i click on Action, Then it must appear like this, 当我点击Action时,它必须显示为这样,

ID | Name | DOB | Select| Reject|

Please help in this 请帮忙

Here's a base example to help you out. 这是一个帮助你的基本示例。

I made a fiddle, with a table with 2 td 我做了一个小提琴,有一个2 td的桌子

<table>
    <tr><td>1</td><td id='td2'>2</td></tr>
</table>

Then i binded a click event on the second td so that when you click it, it removes the last td of each row and adds 2 extra td's. 然后我在第二个td上绑定了一个click事件,这样当你点击它时,它会移除每一行的最后一个td并添加2个额外的td。 Here's the jquery function: 这是jquery函数:

$('#td2').on("click",function(){
    $('tr').each(function(){
        $(this).children('td').last().remove();
        var myTD = "<td>3</td><td>4</td>";
        $(this).append(myTD);
    });
})

here's a jsfiddle: example 这是一个jsfiddle: 例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM