在使用jQuery对话框删除网格视图行的过程中,可能会涉及到以下几个基础概念:
以下是一个简单的示例,展示了如何使用jQuery UI的对话框组件来删除网格视图中的一行数据:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jQuery Dialog Delete Row Example</title>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>
<table id="gridView" border="1">
<tr>
<th>ID</th>
<th>Name</th>
<th>Action</th>
</tr>
<tr>
<td>1</td>
<td>Item 1</td>
<td><button class="delete-btn" data-id="1">Delete</button></td>
</tr>
<!-- More rows here -->
</table>
<div id="deleteDialog" title="Confirm Delete">
<p>Are you sure you want to delete this item?</p>
</div>
<script>
$(function() {
$("#deleteDialog").dialog({
autoOpen: false,
modal: true,
buttons: {
"Delete": function() {
var rowId = $(this).data('id');
$(this).closest('tr').remove();
$(this).dialog("close");
},
"Cancel": function() {
$(this).dialog("close");
}
}
});
$(".delete-btn").click(function() {
var rowId = $(this).data('id');
$("#deleteDialog").data('id', rowId).dialog("open");
});
});
</script>
</body>
</html>
通过以上步骤,你可以创建一个简单的删除确认对话框,并在用户确认后从网格视图中删除相应的行。
领取专属 10元无门槛券
手把手带您无忧上云