在Chrome和Firefox中不会触发Mousedown事件

时间:2014-06-13 13:17:33

标签: javascript jquery google-chrome firefox

我有一个非常讨厌的问题。 在Chrome和Firefox的最后一个版本中,mousedown事件都没有被触发。 IE 11工作正常。 http://jsfiddle.net/CyzT8/

稍后我想添加和删除小部件,因此我无法使用工作提取。

        // DOES NOT WORK in Chrome and Firefox
        //$("#content_wrapper").mousedown(".resizer", function (e) {
        //    e.preventDefault();
        //    resizing = true;
        //    frame = $(this).parent();
        //});

        // DOES work in all browsers
        $(".resizer").mousedown(function (e) {
            e.preventDefault();
            resizing = true;
            frame = $(this).parent();
        });

2 个答案:

答案 0 :(得分:2)

我不认为你可以在.mousedown()事件中以这种方式传递选择器。请参阅http://api.jquery.com/mousedown/处的文档。所以以下几点都没有成功:

$("#content_wrapper").mousedown(".resizer", function (e) {
    e.preventDefault();
    resizing = true;
    frame = $(this).parent();
});

在你的小提琴中,第二个在Chrome中对我很好,我相信是正确的。

$("#content_wrapper").on("mousedown", ".resizer", function (e) {
    e.preventDefault();
    resizing = true;
    frame = $(this).parent();
});

答案 1 :(得分:0)

试试这个:

$("#content_wrapper").mousedown(".resizer", function (e) {
   e.preventDefault();
   resizing = true;
   frame = $(e.target).parent();
});
相关问题