Which JS file to be included to use the function of dialog

此生再无相见时 提交于 2020-01-17 08:16:32

问题


I want to open a dialog box for confirmation on click of a button. For that I am using the following code

$('#dialog-box').dialog({
                show : 'drop',

....

where #dialog-box is an ID for button. Now I am getting an error: Uncaught TypeError: Object [object Object] has no method 'dialog'

Which js File need to be included so that this error is removed


回答1:


The .dialog() function is part of JQuery UI.

Here's a library from Google's CDN.
To make sure that you get everything that you need for JQuery UI, you can download it from here or use their online hosted scripts from here.

Here's a sample script

Note the order in which I retrieve the libraries and then execute the script:

  1. JQuery
  2. JQuery UI
  3. Initialize dialog box
<!-- JQuery UI stylesheet --> 
<link rel="stylesheet" href="http://code.jquery.com/ui/1.8.18/themes/base/jquery-ui.css" type="text/css" media="all" />

<!-- First get JQuery -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<!-- Then get JQuery UI -->
<script src="http://code.jquery.com/ui/1.8.18/jquery-ui.min.js"></script>

<script>
    $(function() {
        $( "#dialog-box" ).dialog({
            width: "auto",
            height: "auto"
        });
    });
</script>

<div id="dialog-box" title="Getting down with dialog boxes">
    <p>This is how you initialize and use the dialog box.</p>
</div>


来源:https://stackoverflow.com/questions/10024775/which-js-file-to-be-included-to-use-the-function-of-dialog

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