jQuery - 在初始化之前无法调用对话框中的方法 [英] jQuery - cannot call methods on dialog prior to initialization

查看:404
本文介绍了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

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

这篇关于jQuery - 在初始化之前无法调用对话框中的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆