2014-06-13 27 views
1

我有一個非常惱人的問題。 在Chrome和Firefox都是最新版本中,mousedown事件未被觸發。 IE 11工作正常。 http://jsfiddle.net/CyzT8/Mousedown事件並未在Chrome和Firefox中被解僱

後來我想添加和刪除小部件,所以我不能使用工作提取。

 // 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(); 
     }); 
+0

e.preventDefault()後面的代碼將不會被執行。 – Danyu

+0

您的第二個註釋事件處理程序[適用於我](http://jsfiddle.net/CyzT8/6/)在Chrome和Firefox每晚。什麼似乎是這個問題? – thykka

+4

使用[jQuery's'on'](http://api.jquery.com/on/)進行事件委託。 ['mousedown()',根據文檔](http://api.jquery.com/mousedown/),顯然不會縮寫它。 – blgt

回答

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(); 
}); 
0

試試這個:

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