我想在删除用户时在确认对话框窗口中获取下一个表格单元格文本。
即。 “你确定要删除用户名吗?”
到目前为止,我有这个(示例简化):
HTML
<table>
<tr>
<th></th>
<th>Id</th>
<th>Name</th>
</tr>
<tr>
<td><a class="deleteUser" href="#">Delete</a></td>
<td>1</td>
<td>Name1</td>
</tr>
<tr>
<td><a class="deleteUser" href="#">Delete</a></td>
<td>2</td>
<td>Name2</td>
</tr>
</table>
的Javascript
$(function() {
$(".deleteUser").click(function() {
confirm("Are you sure you want to delete ?")
});
});
的jsfiddle http://jsfiddle.net/EARRt/
答案 0 :(得分:2)
var username = $(this).parent().parent().find('.names').text();
confirm("Are you sure you want to delete " + username + "?")
这是一个有效的fiddle
答案 1 :(得分:1)
检查此链接mike
这是你的HTML
<tr>
<th></th>
<th>Id</th>
<th>Name</th>
</tr>
<tr>
<td><a class="deleteUser" href="#">Delete</a></td>
<td>1</td>
<td>Name1</td>
</tr>
<tr>
<td><a class="deleteUser" href="#">Delete</a></td>
<td>2</td>
<td>Name2</td>
</tr>
这是jquery应该看起来像
$(function() {
$(".deleteUser").click(function() {
confirm("Are you sure you want to delete "+$(this).parent().next().next()[0].innerText+"?")
});
});