jQuery - 在初始化之前无法调用对话框中的方法
这一个真的在欺骗我。我的控制台中出现错误:未捕获错误:在初始化之前无法调用对话框中的方法;尝试调用方法close
This one is really bugging me. I'm getting an error in my console of Uncaught Error: cannot call methods on dialog prior to initialization; attempted to call method 'close'
$( function() {
$('#search_all_notes_input').dialog({
autoOpen: false,
show: {
effect: "blind",
duration: 1000
},
hide: {
effect: "explode",
duration: 1000
}
});
/* Make the Search div a button and open dialog on click */
$( "#search_all_button" ).button().click(function() {
$( "#search_all_notes_input" ).dialog( "open" );
});
});
$('#submit_search_all_button').click( function () {
var searchText = $('#search_all_text').val();
var query = location.search.split('=');
var urlMrn = query[1];
formData = { mnr: urlMRN, search_text: searchText };
console.log(formData);
//$.post('note_search.php', formData, getMatchedNotes(data));
$(this).dialog('close');
});
任何想法?我在对话框div中使用了一个按钮元素,而不是一个自定义的对话框按钮。此外,脚本在我的HTML页面的最后加载
Any ideas? I'm using a button element inside my dialog div instead of a custom dialog button. Also, the script is loaded at the very end of my HTML page
问题是您正在调用对话框('close')
在 #submit_search_all_button
按钮,而不是 #search_all_notes_input $ c $你最初创建一个对话框的元素
The problem is you're calling the dialog('close')
on the #submit_search_all_button
button, not the #search_all_notes_input
element that you originally created a dialog on.
而不是 $(this).dialog('close');
,使用这个:
$('#search_all_notes_input').dialog('close');