Error: TypeError: $(…).dialog is not a function

后端 未结 7 1595
半阙折子戏
半阙折子戏 2020-11-27 06:29

I am having an issue getting a dialog to work as basic functionality. Here is my jQuery source imports:



        
相关标签:
7条回答
  • 2020-11-27 06:51

    I had a similar problem and in my case, the issue was different (I am using Django templates).

    The order of JS was incorrect (I know that's the first thing you check but I was almost sure that that was not the case, but it was). The js calling the dialog was called before jqueryUI library was called.

    I am using Django, so was inheriting a template and using {{super.block}} to inherit code from the block as well to the template. I had to move {{super.block}} at the end of the block which solved the issue. The js calling the dialog was declared in the Media class in Django's admin.py. I spent more than an hour to figure it out. Hope this helps someone.

    0 讨论(0)
  • 2020-11-27 06:58

    I just experienced this with the line:

    $('<div id="editor" />').dialogelfinder({
    

    I got the error "dialogelfinder is not a function" because another component was inserting a call to load an older version of JQuery (1.7.2) after the newer version was loaded.

    As soon as I commented out the second load, the error went away.

    0 讨论(0)
  • 2020-11-27 07:00

    If you comment out the following code from the _Layout.cshtml page, the modal popup will start working:

        </footer>
    
        @*@Scripts.Render("~/bundles/jquery")*@
        @RenderSection("scripts", required: false)
        </body>
    </html>
    
    0 讨论(0)
  • 2020-11-27 07:03

    Change jQueryUI to version 1.11.4 and make sure jQuery is not added twice.

    0 讨论(0)
  • 2020-11-27 07:05

    Here are the complete list of scripts required to get rid of this problem. (Make sure the file exists at the given file path)

       <script src="@Url.Content("~/Scripts/jquery-1.8.2.js")" type="text/javascript">
        </script>
        <script src="@Url.Content("~/Scripts/jquery-ui-1.8.24.js")" type="text/javascript">
        </script>
        <script src="@Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript">
        </script>
        <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript">
        </script>
        <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript">
        </script>
    

    and also include the below css link in _Layout.cshtml for a stylish popup.

    <link rel="stylesheet" type="text/css" href="../../Content/themes/base/jquery-ui.css" />
    
    0 讨论(0)
  • 2020-11-27 07:13

    Be sure to insert full version of jQuery UI. Also you should init the dialog first:

    $(function () {
      $( "#dialog1" ).dialog({
        autoOpen: false
      });
      
      $("#opener").click(function() {
        $("#dialog1").dialog('open');
      });
    });
    <script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
     
    <script src="https://code.jquery.com/ui/1.11.1/jquery-ui.min.js"></script>
    
    <link rel="stylesheet" href="https://code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css" />
    
    <button id="opener">open the dialog</button>
    <div id="dialog1" title="Dialog Title" hidden="hidden">I'm a dialog</div>

    0 讨论(0)
提交回复
热议问题