,如果你不想這也做的伎倆有一個循環:
$(".element").dialog({
modal: true,
autoOpen: false,
buttons: {
"I've read and understand this": function() {
$(this).dialog("close");
}
}
}).dialog("option", "appendTo", $(".element").closest('.container'));
$('a').click(function(){
$(".element").dialog('open');
});
甚至更短(和更便宜,因爲你只能遍歷一次DOM尋找.element
):
var elem = $(".element")
elem.dialog({
modal: true,
appendTo: elem.closest('.container'),
autoOpen: false,
buttons: {
"I've read and understand this": function() {
$(this).dialog("close");
}
}
})
$('a').click(function(){
elem.dialog('open');
});
謝謝。好一個! – VladRia