I have several links on the page and I want to show separate jQuery dialogs for each of them. Here is the markup:
<html>
<body>
<div class="container">
<a href="#" class="delete_link">delete</a>
<div class="dialog_box">
Pleasy specify a reson for your action
<textarea rows="5" cols="60"></textarea>
</div>
</div>
<div class="container">
<a href="#" class="delete_link">delete</a>
<div class="dialog_box">
Pleasy specify a reson for your action
<textarea rows="5" cols="60"></textarea>
</div>
</div>
</body>
</html>
And Javascript:
$(document).ready(function() {
$('.delete_link').click(function() {
alert('about to show jQuery dialog!');
var d = $(this).closest('DIV.container').find('DIV.dialog_box').dialog({
autoOpen: false,
title: 'You are going to delete a div!',
buttons: {
"Do delete": function() {
alert('You have entered:' + $(this).find('textarea').val());
$(this).dialog("close");
$(this).closest('DIV.container').hide();
}
},
width: 800
});
d.dialog("open");
});
});
As you can see, the links that trigger the event have a delete_linkclass and the DIVs, which should be jQuery UI dialogs, have a class dialog_box.
Problem: when Dialog opens and the user clicks “close”, it is not possible to open the dialog again.
google SO . , : http://blog.nemikor.com/2009/04/08/basic-usage-of-the-jquery-ui-dialog/
, - click(), id - .
, :
$(document).ready(function() {
$('DIV.dialog_box').dialog({
autoOpen: false,
title: 'You are going to delete a div!',
buttons: {
"Do delete": function() {
alert('You have entered:' + $(this).find('textarea').val());
$(this).dialog("close");
$(this).closest('DIV.container').hide();
}
},
width: 800
});
$('.delete_link').click(function() {
alert('about to show jQuery dialog!');
$(this).closest('DIV.container').find('DIV.dialog_box').dialog("open");
});
});
jsFiddle: http://jsfiddle.net/NQmhk/
jQuery UI css, , , .
.