I am using the Jquery UI dialog box to act as a confirmation when deleting a record. What I'm trying to achieve is that when you click on a submit button with the value "delete" it will open the dialog window and confirm your choice. If you choose yes it will submit the form with the value of the submit button. I understand that it won't work at the moment because submit() has no way of knowing which button was clicked but I'm not sure how to go about it? Many thanks in advance.
我正在使用Jquery UI对话框在删除记录时充当确认。我想要实现的是当你点击一个值为“delete”的提交按钮时,它将打开对话框窗口并确认你的选择。如果您选择是,它将提交带有提交按钮值的表单。我知道它目前无法正常工作,因为submit()无法知道点击了哪个按钮,但我不知道该怎么办呢?提前谢谢了。
<script type="text/javascript">
$(document).ready(function(){
$("#dialog").dialog({
modal: true,
bgiframe: true,
width: 500,
height: 200,
autoOpen: false
});
$("#rusure").click(function(e) {
e.preventDefault();
$("#dialog").dialog('option', 'buttons', {
"Confirm" : function() {
$("#tasks").submit();
},
"Cancel" : function() {
$(this).dialog("close");
}
});
$("#dialog").dialog("open");
});
});
</script>
<input type="submit" name="action" value="Delete" id="rusure"/>
The form is called "tasks" and the hidden div containing the dialog content is called "dialog". At the moment everything is working fine apart from the form being submitted with the value of the submit button. There are also 2 submit buttons in the form.
表单称为“任务”,包含对话框内容的隐藏div称为“对话框”。目前,除了提交的表单与提交按钮的值之外,一切正常。表格中还有2个提交按钮。
1 个解决方案
#1
1
Give this a try:
尝试一下:
$("#rusure").click(function(e) {
e.preventDefault();
// Create hidden input from button and append to form
var input = $('<input name="confirm_delete" value="yesplz" type="hidden" />').appendTo('#tasks');
$("#dialog").dialog('option', 'buttons', {
"Confirm" : function() {
$("#tasks").submit();
},
"Cancel" : function() {
$(this).dialog("close");
$(input).remove();// Remove hidden input
}
});
$("#dialog").dialog("open");
});
Demo here: http://jsfiddle.net/Madmartigan/ZGLNc/1/
在这里演示:http://jsfiddle.net/Madmartigan/ZGLNc/1/
#1
1
Give this a try:
尝试一下:
$("#rusure").click(function(e) {
e.preventDefault();
// Create hidden input from button and append to form
var input = $('<input name="confirm_delete" value="yesplz" type="hidden" />').appendTo('#tasks');
$("#dialog").dialog('option', 'buttons', {
"Confirm" : function() {
$("#tasks").submit();
},
"Cancel" : function() {
$(this).dialog("close");
$(input).remove();// Remove hidden input
}
});
$("#dialog").dialog("open");
});
Demo here: http://jsfiddle.net/Madmartigan/ZGLNc/1/
在这里演示:http://jsfiddle.net/Madmartigan/ZGLNc/1/