jQuery - cannot call methods on dialog prior to initialization

早过忘川 提交于 2019-12-11 13:10:35

问题


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');
});

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


回答1:


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.

Instead of $(this).dialog('close');, use this:

$('#search_all_notes_input').dialog('close');


来源:https://stackoverflow.com/questions/17902578/jquery-cannot-call-methods-on-dialog-prior-to-initialization

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!