0

我正在使用 Jquery Live 绑定将单击事件绑定到图像。我第一次单击图像时,simplemodal 弹出窗口启动并且可拖动工作正常。之后,simplemodal 弹出窗口仍会启动,并且可拖动项目不会拖动。有任何想法吗?

实时点击事件代码:

$("table tr td img:not(.Help)").live("click", function(){

    $("#draggable").draggable({
        containment: 'parent',
        drag: function(e, ui){
            alert("dragging");
        }
    });

    $("#modal").modal({
        onShow: function(){
            $("html").css("overflow", "hidden");
        },
        onClose: function(){
            $("html").css("overflow", "auto");
            $("table tr td img").live("click", function(){});
            $.modal.close();
        }
    });
});
4

1 回答 1

3

万一有人在未来寻找这个,解决方案是将“可拖动”代码放在 onShow 回调中。

$("table tr td img:not(.Help)").live("click", function(){ 

    $("#modal").modal({ 
        onShow: function(){
             $("#draggable").draggable({ 
                containment: 'parent', 
                drag: function(e, ui){ 
                    alert("dragging"); 
                } 
            });  
            $("html").css("overflow", "hidden"); 
        }, 
        onClose: function(){ 
            $("html").css("overflow", "auto"); 
            $("table tr td img").live("click", function(){}); 
            $.modal.close(); 
        } 
    }); 
}); 
于 2010-02-05T19:55:58.337 回答