我刚刚开始学习jQuery,它似乎充满了机会,如果我可以学习它的话。
我创建了一个表格,其中最后一个单元格包含删除按钮。通过单击按钮,我希望出现一个确认对话框,如果用户接受,该行将被删除。取消只是关闭确认对话框。
但我不知道如何做到这一点,即使在阅读了在 stackoverflow 或其他网站上发布的许多示例之后。我只是无法使这些适应我的项目。所以,我喜欢在这件事上得到指导。
我的脚本现在看起来像这样:
<script>
$(document).ready(function(){
$("#dlgConfirm").hide();
});
$(function() {
$("#dlgLink").click(function(){
$( "#dlgConfirm" ).dialog({
resizable: false,
height:140,
modal: true,
buttons: {
"Delete selected toon": function() {
$( this ).dialog( "close" );
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
});
});
</script>
一个 html 包含这些:
<div class="modalForm">
<div id="toons-contain" class="ui-widget">
<h1>Toons:</h1>
<table id="toons" class="ui-widget ui-widget-content">
<thead>
<tr class="ui-widget-header ">
<th class="date">Date</th>
<th class="name">Name</th>
<th class="note">Note</th>
<th class="del">Delete?</th>
</tr>
</thead>
<tbody>
<tr id="row_1">
<td>02.03.2011</td>
<td>Michael</td>
<td>Driving with KITT</td>
<td><a href="#" id="dlgLink" class="ui-state-default ui-corner-all">Delete</a></td>
</tr>
<tr id="row_2">
<td>05.03.2011</td>
<td>Dredd</td>
<td>Criminal hunting</td>
<td><a href="#" id="dlgLink" class="ui-state-default ui-corner-all">Delete</a></td>
</tr>
</tbody>
</table>
</div>
</div>
<div id="dlgConfirm" title="Delete the selected toon?">
<p>
<span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>
Toon will be deleted and cannot be recovered. Are you sure?
</p>
</div>
这将很好地完成表格并通过单击确认对话框打开的删除按钮。
那么你能帮我删除用户点击它的行吗?