我想打开一个jQuery UI对话框,其中的HTML已由ajax加载,但我只得到警报。如何打开ajax加载的jQuery UI对话框?
$(document).on("click",'#dialog-button',function(){
alert('this works');
$('#dialog').dialog('open');//this doesn't
});
当我不使用ajax(和.on)将模板放入模板中时,我没有遇到任何问题。
对话框HTML由AJAX加载喜欢这个东西simular:
$.ajax({
type: "GET",
dataType: "json",
url: href,
success: function(data){
$('#dialog-container').html(data.dialog);
}
});
而且在我的PHP,我会做这样的事情:
<?php
//assign some variables
$array = array('dialog' => $this->smarty->fetch('dialog.tpl'));
echo json_encode($array);
?>
这工作:
$(document).on("click",'#dialog-button',function(){
alert('this works');
$('#dialog').dialog({
autoOpen : true,
height : 500,
width : 1000,
modal : true,
buttons : {
save : function() {
sendForm();
$(this).dialog('close');
},
cancel : function() {
$(this).dialog('close');
},
close : function(){
allFields.vall('').removeClass('ui-sate-error');
},
}
})
})
你有没有包含jQuery Ui lib?并且似乎有一个额外的'});'。 – Jai 2013-03-11 18:00:56
我使用的谷歌图书馆 – Tim 2013-03-11 18:32:13