Leser: 19
1
2
3
4
<form action="instance.cgi" class="del_form">
<input type="hidden" name="id" value="x" />
<input type="submit" value="del" />
</form>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>modal dialog test</title>
<link type="text/css" href="jquery-ui-1.7.2.custom.css" rel="stylesheet" />
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="jquery-ui-1.7.2.custom.min.js"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
});
function my_dialog() {
var dialog_response = true;
$("#dialog").dialog({
bgiframe: true,
resizable: false,
height:140,
modal: true,
overlay: {
backgroundColor: '#000',
opacity: 0.5
},
buttons: {
'Delete all items in recycle bin': function() {
$(this).dialog('close');
dialog_response = true;
},
Cancel: function() {
$(this).dialog('close');
dialog_response = false;
}
}
});
return dialog_response;
} // my_dialog
</script>
</head>
<body>
<div id="dialog" title="Empty the recycle bin?" style="display: none;">
<p>
<span class="ui-icon ui-icon-alert"
style="float:left; margin:0 7px 20px 0;"></span>
These items will be permanently deleted and cannot be
recovered. Are you sure?
</p>
</div>
<form action="test.html" class="del_form" onsubmit="my_dialog()">
<input type="submit" value="del 1" />
</form>
<form action="test.html" class="del_form" onsubmit="my_dialog()">
<input type="submit" value="del 2" />
</form>
</body>
</html>
1
2
3
4
$('#form').submit(function(event){
event.preventDefault();
// Hier dein Code was du stattdessen machen möchtest.
});
1
2
3
4
5
$('.selector').dialog({
close: function(event, ui) {
// Dieser Callback wird ausgeführt wenn der Dialog geschlossen wird.
}
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$('#dialog').dialog({
bgiframe: true,
resizable: false,
height:140,
modal: true,
overlay: {
backgroundColor: '#000',
opacity: 0.5
},
buttons: {
'Delete all items in recycle bin': function() {
$(this).dialog('close');
},
Cancel: function() {
$(this).dialog('close');
}
},
close: function(event, ui) {
alert("close trigger");
}
});
1
2
3
4
5
6
$(document).ready(function() {
$('.del_form').submit(function(){
// mach was
alert("abschicken / nicht abschicken?");
});
});
1
2
3
4
5
6
buttons: {
'Delete all items in recycle bin': function() {
$(this).dialog('close');
dialog_response = true;
$('.del_form').submit;
},
QuoteEs bleibt für mich das Problem, dass ich einfach schlichtweg keine Ahnung habe, wie ich abhängig vom gedrückten Button des Dialogs das Absenden des Formulars verhindere / zulasse. Wie geht das denn?
event.preventDefault();
1
2
3
4
5
6
7
8
$(document).ready(function() {
$('.del_form').submit(function(event){
// DIE NACHFOLGENDE ZEILE BRICHT DEN SUBMIT AB
event.preventDefault()
// mach was
alert("abschicken / nicht abschicken?");
});
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$('.del_form').submit(function(event){
event.preventDefault();
var response = true;
$('#dialog').dialog({
bgiframe: true,
resizable: false,
height:140,
modal: true,
overlay: {
backgroundColor: '#000',
opacity: 0.5
},
buttons: {
'Delete all items in recycle bin': function() {
response = true;
$(this).dialog('close');
},
Cancel: function() {
response = false;
$(this).dialog('close');
}
},
close: function(event, ui) {
if( response ) {
// decide to submit by releasing this event
$('.del_form').unbind('submit').submit()
}
}
});
});
return false;
});
</script>
$('#form').submit();
$('.del_form').unbind('submit').submit();