我正在上雙擊編輯表的TD
元素:暫時禁用所有當前活動的jQuery的事件處理程序
$(document).on("dblclick", "#table>tbody>tr>td.cell", function(e) {
if (e.which != 1 || e.shiftKey || e.altKey || e.ctrlKey)
// need left button without keyboard modifiers
return;
reset_selection();
var editor = document.createElement("div");
editor.setAttribute("contenteditable", "true");
editor.innerHTML = this.innerHTML;
this.innerHTML = '';
// this.style.padding = 0;
this.appendChild(editor);
$(document).on("*", stub);
editor.onblur = function() {
// this.parentNode.setAttribute("style", "");
this.parentNode.innerHTML = this.innerHTML;
sys.editor = null;
$(document).off("*", stub);;
};
editor.focus();
});
function stub(e) {
e.stopImmediatePropagation();
return false;
}
但是,當我雙擊可編輯的DIV中的文本,則雙擊事件傳播到父母td造成不良後果。還有其他的事件(select
,mousedown
等),我想要防止,所以爲他們每個人寫一個存根並不看好我。
有沒有一種方法來禁用所有當前活動的jQuery的事件處理程序之後允許它們?或者有人停止將可編輯div的所有事件傳播給其父母?
如果'td'的父母之一也有一些處理程序會怎樣?我是否也爲他們每個人做了一個存根? – warvariuc 2013-02-13 08:57:15
@warwaruk:不需要,'false'停止傳播。 – 2013-02-13 08:58:47
我有'