【问题标题】:Mousedown event is not fired in Chrome and Firefox在 Chrome 和 Firefox 中不会触发 Mousedown 事件
【发布时间】:2014-06-13 13:17:33
【问题描述】:

我有一个非常烦人的问题。 在 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();
        });

【问题讨论】:

  • e.preventDefault() 之后的代码不会被执行。
  • 您的第二个在 Chrome 和 Firefox 中每晚注释掉事件处理程序 works for me。似乎是什么问题?
  • 使用jQuery's on 进行事件委托。 mousedown(), according to the documentation,显然没有简写。
  • 不是答案,而是建议。如果您希望任何人能够拖动它们,请将黑色部分增加到 2 个像素以上。它很烦人。哈哈

标签: javascript jquery google-chrome firefox


【解决方案1】:

我认为您不能以这种方式在 .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();
});

【讨论】:

    【解决方案2】:

    试试这个:

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

    【讨论】:

      猜你喜欢
      • 2016-05-30
      • 2013-12-20
      • 2012-05-10
      • 1970-01-01
      • 1970-01-01
      • 2023-03-17
      • 2016-10-21
      • 1970-01-01
      • 2012-02-10
      相关资源
      最近更新 更多