拖放事件时如何调用click事件

时间:2013-06-21 09:23:43

标签: javascript jquery

我想要更改事件拖放,单击我的对象的事件。 我试试这段代码

 $("a").draggable({
    start: function (event, ui) {
        $(this).trigger("click");
    }
});

但不行:(

更新

我试试这段代码:

document.ondragstart = function () {
return false;
};

document.onmouseup = function (a, b) {
$(this).trigger("click");
};

但触发点击仍无法正常工作

2 个答案:

答案 0 :(得分:1)

尝试进行此修改:

$("a").draggable({
    start: function (event, ui) {
        $(--your-button-element-here-).click();
    }
});

答案 1 :(得分:0)

我找到了这样一个解决方案

var url = null;
        $("a").mousedown(function () {
            url = $(this).attr("href");
            $(window).mousemove(function () {
                $(window).unbind("mousemove");
            });
        });
        $(window).mouseup(function () {
            $(window).unbind("mousemove");
            if (url != null) {
                location.href = url;
            }
        });