0
我有一個函數,可以在填寫表單後刷新頁面上的內容。它的作品,但jQuery的移動元素沒有格式化。調用trigger()不起作用,因爲顯然它在元素出現在頁面上之前被調用。下面的代碼:你如何在加載了ajax的內容上運行觸發器(「創建」)?
function add_note() {
var vid = $("#basic_note_vid_hidden").val();
note = $("#basic_note_textarea").val().replace(/(\r\n|\n|\r)/gm,"<br />");
$.ajax({
async: true,
type: "POST",
url: "ajax.pl",
data: "action=add_note&vid=" + vid + "¬e=" + note,
error: function(res) {
$.growl({title:"Update failed!", style: "error",message:"Are you connected to the Internet?", static:true, size: 'medium' })
},
success: function(res) {
$.growl({title:"Update successful", message:"Note added", duration:500, size: 'small' });
$("#basic_note_close_button").click();
$("#basic_note_textarea").val('');
$("#notes .ui-content").load('ajax.pl?action=print_note_ajax&vid=' + vid).parent().trigger('create');
},
});
}
事情的肉是代碼的最後一行。有沒有辦法檢測新內容何時加載到頁面中,以便我知道何時可以調用trigger()函數?