gpt4 book ai didi

javascript - 如何在javascript上获取单元格值进行确认?

转载 作者:行者123 更新时间:2023-11-28 06:46:33 25 4
gpt4 key购买 nike

我有一个 html 代码,我希望当我单击“删除”时删除当前行,然后显示确认“您要删除 [姓名]?”那么,当我使用 Jquery 单击删除时,如何获取名称值进行确认呢?

<table id="tblInfo">

<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Birthday</th>
<th></th>
</tr>
</thead>

<tbody>
<tr>
<td>1</td>
<td>Name1</td>
<td>01/01/1990</td>
<td>
<a href="#" class="btnView" >View</a>
<a href="#" class="btnDelete">Delete</a>
</td>
</tr>
<tr>
<td>2</td>
<td>Name2</td>
<td>01/01/1990</td>
<td>
<a href="#" class="btnView">View</a>
<a href="#" class="btnDelete">Delete</a>
</td>
</tr>
</tbody>

<tfoot>
<tr>
<td></td>
<td><input type="text" name="" value="" size="25" /></td>
<td><input type="text" name="" value="" size="25" /></td>
<td>
<a href="#" class="btnAdd">Add</a>
</td>
</tr>
</tfoot>
</table>

最佳答案

演示:http://jsfiddle.net/1qda1jpx/1/

$(document).ready(function() {
$("#tblInfo").on("click", ".btnDelete", function() {
var $this = $(this);
var name = $this.closest("tr").find("td:nth-child(2)").text(); // gets the name of the row
if (confirm("Do you want to delete" + name + "?"))
{ $this.closest('tr').remove(); } // upon confirmation, remove the row
});
});

关于javascript - 如何在javascript上获取单元格值进行确认?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33374279/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com