【发布时间】:2009-08-07 00:37:52
【问题描述】:
我动态生成了一个表格,如下所示:
命名动作
==== =======
亚当删除
乔删除
账单删除
我希望“删除”是一个弹出确认弹出窗口的链接:
“您确定要删除“Adam”吗?(是,否)
请注意,“adam”是上下文相关的,需要从用户选择它的表的行中检索。
【问题讨论】:
标签: asp.net javascript jquery html
我动态生成了一个表格,如下所示:
命名动作
==== =======
亚当删除
乔删除
账单删除
我希望“删除”是一个弹出确认弹出窗口的链接:
“您确定要删除“Adam”吗?(是,否)
请注意,“adam”是上下文相关的,需要从用户选择它的表的行中检索。
【问题讨论】:
标签: asp.net javascript jquery html
类似这样的:
$(document).ready(function() {
$('a.delete').click(function(e) {
//prevent the link from going anywhere
e.preventDefault();
//give me this link's parent (a <td>) and grab the text of the 'prev' one
var name = $(this).parent().prev('td').text();
var answer = confirm("Are you sure you want to delete " + name);
});
});
假设您将删除链接指定为 delete 类。
这应该适用于您提到的每个表结构。
<html>
<head>
<!-- you will need jQuery -->
<script type='text/javascript' src='path/to/jquery.js' ></script>
<script type='text/javascript'>
$(function() {
$("td[innerHTML*='delete']").click(function(e) {
var name = $(this).prev('td').text();
if( confirm("Are you sure you want to delete " + name) )
{
// call ajax to delete this record
// remove tr element
$(this).parent().remove();
}
});
});
</script>
</head>
<body>
<!-- your table -->
<table>
<tr>
<td>Mira</td>
<td>delete</td>
</tr>
<td>Adam</td>
<td>delete</td>
<tr>
<td>Barney</td>
<td>delete</td>
</tr>
<tr>
<td>Scott</td>
<td>delete</td>
</tr>
</table>
</body>
</html>
【讨论】: