【问题标题】:Jquery draggable stops after IE AJAX refreshIE AJAX刷新后Jquery可拖动停止
【发布时间】:2011-02-12 10:46:08
【问题描述】:

我有一个网页,我通过单击按钮从文本创建图像并将图像添加到父 div 元素中的可拖动 div。 div 位于更新面板中。在此事件之后,div 是可拖动的。当我添加另一个图像-> 文本时,我有另一个按钮可以临时保存 html 并使用它们的位置重新创建 div。然而,在此事件之后,所有旧 div 都失去了它们的拖动属性,最后添加的 div 仍保留可拖动属性。

 $(".inner").live('mousedown', function() {
    $(this).draggable({
              containment: "#<%=divMain.ClientID%>",
        cursor: "move",
        stop: function(event, ui) {
             var position = $(this).position();
            $(this).css("top", position.top + 'px');
            $(this).css("left",position.left + 'px');
        }
    });
});

这是我目前的功能。请建议!这在 Firefox 和 chrome 中完美运行。问题仅在 IE 中。

【问题讨论】:

    标签: jquery jquery-ui asp.net-ajax jquery-ui-draggable


    【解决方案1】:

    感谢您的建议,我找到了解决方案,当我通过 ajax[postback] 动态添加 div 时,我销毁了所有已添加的 div 的 draggble。$('.draggable').draggable('destroy' ); 然后使用 live 函数重新分配可拖动函数 $(".draggable'").live('mousedown click', function() {...}); 完美运行。

    【讨论】:

      【解决方案2】:

      这是因为 jquery 在部分回发后丢失了它的事件。 试试这种方式,

      function pageLoad() { $(".inner").live('mousedown', function() { $(this).draggable({ containment: "#<%=divMain.ClientID%>", cursor: "move", stop: function(event, ui) { var position = $(this).position(); $(this).css("top", position.top + 'px'); $(this).css("left",position.left + 'px'); } }); }); }

      【讨论】:

      • 谢谢您,我之前尝试过,但似乎不起作用。我尝试使用 ScriptManager.RegisterStartupScript(this.Page, this.GetType(), Guid.NewGuid().ToString(), "Test();", true); 重新注册函数。但无济于事。
      • 尝试将你的函数放入 Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestFunctionHandler);
      猜你喜欢
      • 2012-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-05
      • 2015-09-25
      • 2012-03-05
      • 2013-07-30
      • 2011-08-04
      相关资源
      最近更新 更多