J'ai des problèmes pour ouvrir la boîte de dialogue div. Lorsque je tente d'ouvrir la boîte de dialogue comme celui-ci, rien ne se passe:JQuery: Impossible d'ouvrir la boîte de dialogue
$(this).closest('div.editable').find('.update-dialog').dialog("open");
Et quand je tente d'accéder à l'élément div de dialogue pour voir si je reçois quoi que ce soit,
alert($(this).closest('div.editable').find('.update-dialog').prop("class"));
Alerte retourne " indéfini". Mais comment cela peut-il être? Le div.update-dialog est un frère de l'élément button (this), donc l'appel de "find" sur le résultat renvoyé par "nearest" devrait me donner div.update-dialog.
Voici le code complet. Les domaines d'intérêt sont marqués par des commentaires:
<!DOCTYPE html>
<html>
<head>
<title>sourcecode test</title>
</head>
<body>
<!-- DIALOG DIV - note the hierarchy/tree of the html elements -->
<div class ="editable" id="div_John E. Coons[instructor_status]"contenteditable="1">
<span class="text-error">Error: More than one user with same fname and lname</span>
<br/>Users:
<br/>
<span class="multiple-users">  Instructor ID: 23, Common Name: John E. Coons</span>
<br/>
<span class="multiple-users">  Instructor ID: 17447, Common Name: John E Coons</span>
<br/>
<div class="update-dialog" title="Update Common Name">Which instructor do you want to update?
<p><input type="radio" id="instructor_23" name="instructor" value="23"/>
<label for="instructor_23">Instructor ID: 23, Common Name: John E. Coons</label>
</p>
<p>
<input type="radio" id="instructor_17447" name="instructor" value="17447"/>
<label for="instructor_17447">Instructor ID: 17447, Common Name: John E Coons</label>
</p>Which common name do you want to assign the instructor?
<p>
<input type="radio" id="commonName_23" name="common_name" value="John E. Coons"/>
<label for="commonName_23">John E. Coons</label>
</p>
<p>
<input type="radio" id="commonName_17447" name="common_name" value="John E Coons"/>
<label for="commonName_17447">John E Coons </label>
</p>
</div>
<button class="update-button" type="button">Update Common Name of an Instructor</button>
</div>
<script src="http://code.jquery.com/jquery-2.0.3.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
$(document).ready(function() {
// creates dialog in div
$("div.update-dialog").dialog({
autoOpen: false,
dialogClass: 'dialogStyle',
resizable: false,
modal: true,
buttons: {
"Update": function() {
//$.load('update_common_name.php',
$(this).dialog("close");
},
Cancel: function() {
$(this).dialog("close");
}
}
});
// FIX THIS: DIALOG DOES NOT OPEN ON CLICK
$('div.editable').on('click', 'button.update-button', function() {
$(this).closest('div.editable').find('.update-dialog').dialog("open");
// alert test returns "undefined"
alert($(this).closest('div.editable').find('.update-dialog').prop("class"));
});
$('input:radio').change(function() {
if ($(this).attr('name') === 'instructor') {
instructor_id = $(this).val();
}
if ($(this).attr('name') === 'common_name') {
common_name = $(this).val();
}
alert(instructor_id + common_name);
});
});
</script>
</body>
</html>
est-il ici sur jsFiddle: http://jsfiddle.net/5fKYn/. Est-ce que le DOM change après que le dialogue a été associé à la div?
Quelqu'un connaître? –
Le DOM change-t-il après que le dialogue a été associé à la div? –