【发布时间】:2012-02-13 03:04:11
【问题描述】:
这是我在 StackOverflow 上的第一个问题,我已经访问了有关 jQuery 对话框和表单的每一个问题,但仍有一个问题。
我正在尝试在我的表单上实现一个 jQuery 确认对话框。窗口实际上没有问题出现,但是当我点击“确认”时,表单没有提交......
这是Javascript:
// Form validation
$(function(){
var currentForm;
$("#dialog-confirm").dialog({
autoOpen: false,
resizable: false,
modal: true,
buttons: {
'Confirm': function(e) {
currentForm.submit();
return true;
},
Cancel: function() {
$(this).dialog('close');
return false;
}
}
});
$("#news-listing").submit(function(e){
currentForm=$(this);
if($("#dialog-confirm").dialog("open"))
{
return false;
}
});
});
还有 HTML
<div id="dialog-confirm" title="Empty the recycle bin ?">
<p><span class="ui-icon ui-icon-alert" style="float:left; margin: 20px 10px 20px 10px;"></span>These items will be permanently deleted and cannot be recovered. Are you sure?</p>
</div>
<form action="news/action/delete" id="news-listing">
<table id="users-listing">
<tr>
<th class="id">ID</th>
<th class="title">Title</th>
<th class="url">URL</th>
<th class="modify">Modify</th>
<th class="checkcell">Delete</th>
</tr>
<tr class='alt'>
<td class='id'>".$news['news_id']."</td>";
<td class='title'>".$news['news_title']."</td>";
<td>".$this->News->get_url($news['news_id'])."</td>";
<td class='modify'><a href="modify/1">Modify</a></td>;
<td><input type="checkbox" name="delete[]" /></td>
</tr>
</table>
<input type="submit" name="submit" />
</form>
提前感谢您的帮助!
编辑: 这是我的新代码,HTML 没有改变。现在我有了对话框,但确认按钮没有提交,取消按钮效果很好。
$(function() {
// Get the current form object
var currentForm = $("#news-listing");
// Initialize dialog
$("#dialog-confirm").dialog({
autoOpen: false,
resizable: false,
modal: true,
buttons: {
'Confirm': function() {
currentForm.submit();
return true;
},
Cancel: function() {
$(this).dialog('close');
return false;
}
}
});
// Validate the form
$("#news-listing").validate({
rules:{
"delete[]":"required"
},
submitHandler: function(e){
$("#dialog-confirm").dialog("open");
}
});
});
【问题讨论】:
-
您是否查看过 Firefox、Chrome 或 Safari 的错误控制台?也许你犯了一个 javascript 错误。
标签: jquery forms user-interface dialog confirmation