代码之家  ›  专栏  ›  技术社区  ›  Coding Duchess

未捕获类型错误:$()。on不是函数

  •  4
  • Coding Duchess  · 技术社区  · 9 年前

    我在我的页面上使用JQuery UI对话框,得到了这个错误

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <title>Test</title>
    
        <script src="Scripts/jquery-1.6.4.js"></script>
        <script src="Scripts/jquery-ui-1.11.4.js"></script>
        <script>
            $(document).ready(function () {
                $(".hlk1").on("click", function () {
                    var linkId = $(this).attr("linkID");
                    alert(linkId);
                    // initialize dialog
                    var dlg = $("#dialog").dialog({
                        autoOpen: false,
                        modal: true,
                        draggable: false,
                        resizable: false,
                        position: ['center', 'top'],
                        height: 380,
                        width: 530,
                        dialogClass: 'ui-dialog-osx',
                        buttons: {
                            "Done": function () {
                            $(this).dialog("close");
                        }
                    }
                });
    
                // load content and open dialog
                dlg.load('page2.html?id=' + linkId).dialog('open');
            });
    });
    </script>
    </head>
    
    <body>
    
    <a href="#" class="hlk1" linkid="305">Click here</a>
    <br/>
    <a href="#" class="hlk1" linkid="890">Click here</a>
    <br/>
    <div id="dialog"></div>
    </body>
    </html>
    

    有人能帮我弄清楚吗?它可能是JQuery版本,但这是通过NuGet包管理器安装的Visual Studio版本

    1 回复  |  直到 9 年前
        1
  •  13
  •   Andrew Brooke    9 年前

    .on() 在jQuery 1.7中引入了,但看起来您运行的是1.6.4。如果您不能更改版本,您应该可以将函数更改为 .click

    $(".hlk1").click(function () {
        ...