javascript - 获取 "Uncaught TypeError: $(...).dialog is not a function"

标签 javascript jquery html

我有以下代码,按下调用 $("#proxy_history_dialog").dialog({ 行的按钮后 - 我不断收到错误 Uncaught TypeError: $(. ..).dialog 不是一个函数。 我搜索了一个解决方案,大多数答案都指向 jquery include block 。我多次尝试更改 jquery 版本,但没有成功。 我在这里错过了什么?

<!DOCTYPE HTML>
<html lang="en">
<head>
    <title>
    Optimize Proxies
 | Upstream Commerce</title>


    <script src="https://code.jquery.com/jquery-3.1.1.js"></script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>


    <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.0/themes/smoothness/jquery-ui.css"/>
    <link rel="stylesheet" type="text/css" href="/static/css/tables_style.css" />


    <link rel="stylesheet" type="text/css"
          href="https://cdn.datatables.net/v/dt/jq-2.2.3/dt-1.10.12/fh-3.1.2/datatables.min.css"/>

    <script type="text/javascript"
            src="https://cdn.datatables.net/v/dt/jq-2.2.3/dt-1.10.12/fh-3.1.2/datatables.min.js"></script>


    <script type="text/javascript" src="/static/script/api_recs.js"></script>


    <style type="text/css">
        tfoot {
            display: table-header-group;
        }
    </style>

</head>
<body>

    <img id="loader" src="/static/img/loader_animation_large.gif" 
    style="
        width:36px; 
        height:36px; 
        display: none;
        position:absolute; 
        top:50%;
        left:50%;
        margin-top:-18px;
        margin-left:-18px;"/>
    <p><a href="/accounts/logout/">Logout</a> | <a href="/accounts/profile/">Home</a></p>

    <div id="title">
        <b style="font-size:200%" ;>Optimize proxies<br></b>
    </div>
    <div id="proxy_history_dialog" title="Proxy history" style="display:none;">
    </div>
    <table id='p_table-id' class="display" cellspacing="0" width="50%">
        <thead>
        <tr>

                <th>Site name</th>

                <th>Site id</th>

                <th>Extraction rate</th>

                <th>Proxy</th>

                <th>Proxy duration</th>

                <th>Proxy history</th>

        </tr>
        </thead>
        <tfoot>
        <tr>

                <th>Site name</th>

                <th>Site id</th>

                <th>Extraction rate</th>

                <th>Proxy</th>

                <th>Proxy duration</th>

                <th>Proxy history</th>

        </tr>
        </tfoot>
        <tbody>

            <tr>

                    <td><span>hp</span></td>

                    <td><span>2198</span></td>

                    <td><span>95.2%</span></td>

                    <td><span>brazil</span></td>

                    <td><span>0 days</span></td>

                <td>
                    <button id="2198" class="get-proxy-history">history</button>
                </td>
            </tr>

            <tr>

                    <td><span>amazon_hp</span></td>

                    <td><span>2199</span></td>

                    <td><span>99.8%</span></td>

                    <td><span>all_std.proxymesh</span></td>

                    <td><span>422 days</span></td>

                <td>
                    <button id="2199" class="get-proxy-history">history</button>
                </td>
            </tr>

            <tr>

                    <td><span>bestonix</span></td>

                    <td><span>-104</span></td>

                    <td><span>93.3%</span></td>

                    <td><span>shader_us</span></td>

                    <td><span>225 days</span></td>

                <td>
                    <button id="-104" class="get-proxy-history">history</button>
                </td>
            </tr>

        </tbody>
    </table>

    <script>
        $(document).ready(function () {
            $(".get-proxy-history").click(function () {
                var uri = "manage/optimize_proxies/get_proxy_history/" + $(this).attr("id") + "/";
                var result = api_get(uri, false, 'POST');
                $("#proxy_history_dialog").html(result[0]);

                $("#proxy_history_dialog").dialog({
                    resizable: true,
                    width: "auto",
                    height: "auto",
                    autoResize: false,
                    modal: false,
                    draggable: true
                });
            });


            ///////////////////////////////////////////////////////////////////
            // Setup column search - add a text input to each footer cell
            $('#p_table-id tfoot th').each(function () {
                var title = $(this).text();
                $(this).html('<input type="text" placeholder="Search ' + title + '" />');
            });

            // DataTable
            var table = $('#p_table-id').DataTable({
                dom: 'l Brtip',
                "aLengthMenu": [
                    [20, 50, 100, -1],
                    [20, 50, 100, "All"]],
                "buttons": [],
                paging: false,
                fixedHeader: true


            });
            // Apply the search
            table.columns().every(function () {
                var that = this;

                $('input', this.footer()).on('keyup change', function () {
                    if (that.search() !== this.value) {
                        that
                            .search(this.value)
                            .draw();
                    }
                });
            });
        });
    </script>





</body>
</html>

最佳答案

放置线

<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

之后

<script type="text/javascript" src="/static/script/api_recs.js"></script>

喜欢:

<script src="https://code.jquery.com/jquery-3.1.1.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.0/themes/smoothness/jquery-ui.css"/>
<link rel="stylesheet" type="text/css" href="/static/css/tables_style.css" /> 
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/jq-2.2.3/dt-1.10.12/fh-3.1.2/datatables.min.css"/>    
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/jq-2.2.3/dt-1.10.12/fh-3.1.2/datatables.min.js"></script>    
<script type="text/javascript" src="/static/script/api_recs.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

注意: 如果这种方式不起作用,请检查 api_recs.js

关于javascript - 获取 "Uncaught TypeError: $(...).dialog is not a function",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41693550/

相关文章:

javascript - 从给定的开始年份开始获取年份列表

javascript - 为什么 jQuery 源代码在其余代码之前关闭?

在 iPad 上滚动时 JavaScript 动画暂停

循环中按属性分组的javascript求和值

jquery - 根据评论密度更改 .accordion 面板的颜色

jquery - 如何调整照片库中照片的大小以减少加载时间?

javascript - React 检测到 Hooks 的调用顺序发生了变化,但我看不到任何有条件调用的 hooks

javascript - jquery如果url包含参数则触发点击

javascript - 在悬停主图像上,宽度不适用于缩放图像,请引用下面的附图

javascript - 调用其他标签的onclick事件