代码之家  ›  专栏  ›  技术社区  ›  Maksim Vi.

jQueryUI Ajax.NET回发错误

  •  2
  • Maksim Vi.  · 技术社区  · 16 年前

    我有 this 带有ASP.NET UpdatePanel和jQueryUI可拖放和可排序组件的ASP.NET页。该页面在所有浏览器中都可以正常工作,但在InternetExplorer(IE8测试版)中则不行。

    尝试调用ASP.NET AJAX事件(通过按UpdatePanel中的ASP.NET按钮)后,IE浏览器中的可排序列表停止正常工作,浏览器抛出以下错误:

    线路:145 字符:186 http://code.jquery.com/jquery-1.4.2.min.js

    我发现问题是由第66行的代码引起的:

    $("#droppable").droppable();
    

    如果我将其注释掉,那么在ajax回发之后,可排序列表可以正常工作。但这毫无意义。

    谢谢。

    另外,我用的是jQueryUI 1.4.2

    2 回复  |  直到 6 年前
        1
  •  1
  •   Robben_Ford_Fan_boy    16 年前

    我相信这是JQuery中的一个bug-我认为有一个修复方法,可以在IE下重新定义offset函数:

    http://dev.jqueryui.com/ticket/4918

    干杯

        2
  •  0
  •   Maksim Vi.    6 年前

    解决方案

    <%@ Page Language="C#" AutoEventWireup="true" %>
     
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
            <style type="text/css">
                    #sortable
                    {
                            list-style-type: none;
                            margin: 0;
                            padding: 0;
                            border: solid 1px #999999;
                    }
                    #sortable li
                    {
                            margin: 0.3em 0.3em 0.3em 0.3em;
                            padding-left: 1.5em;
                            font-size: 1em;
                            height: auto;
                            border: dotted 1px #999999;
                            background-color: #dddddd;
                    }
                    #sortable li:hover
                    {
                            background-color: #aaaaaa;
                    }
            </style>
    </head>
    <body>
            <form id="form1" runat="server">
                    <asp:ScriptManager runat="server" ID="srptManager">
                            <Scripts>
                                    <asp:ScriptReference Path="http://code.jquery.com/jquery-1.4.2.min.js" />
                                    <asp:ScriptReference Path="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js" />
                            </Scripts>
                    </asp:ScriptManager>
                    <asp:UpdatePanel ID="updPanel" runat="server">
                            <ContentTemplate>
                                    <ul id="sortable">
                                            <li>Item 1</li>
                                            <li>Item 2</li>
                                            <li>Item 3</li>
                                            <li>Item 4</li>
                                            <li>Item 5</li>
                                    </ul>
                                    <div id="droppable" style="background-color: black">
                                            Drop Here</div>
                                    <asp:Button runat="server" ID="btnAjaxRefresh" Text="Go" />
                            </ContentTemplate>
                    </asp:UpdatePanel>
     
                    <script type="text/javascript" language="javascript">
                            Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
                            // *******Solution Here*******
                            Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
     
                            function EndRequestHandler(sender, args) {
                                    if (args.get_error() == undefined) {
                                            jqueryStuff();
                                    }
                            }
     
                            function BeginRequestHandler(sender, args) {
                                    $("#sortable").sortable("destroy");
                                    $("#droppable").droppable("destroy");
                            }
     
                            function jqueryStuff() {
                                    $(document).ready(function() {
                                            $("#sortable").disableSelection();
                                            $("#sortable").sortable();
                                            // ******Problem at this line******
                                            $("#droppable").droppable();
                                    });
                            }
     
                            jqueryStuff();
                    </script>
            </form>
    </body>
    </html>