好的,假设我有一个按钮,我想启用/禁用其单击处理程序。

我想创建如下函数:

var bar = [];
function storeHandlers(buttonID) {
    //I would like to store the click handlers in bar[buttonID]
}

function preventHandlers(buttonID) {
    storeHandlers(buttonID);
    //I would like to disable all the click handlers for button
}

function loadHandlers(buttonID) {
    //I would like to enable all the handlers loaded from bar[buttonID]
}

这可能吗?我该如何实现?

先感谢您

最佳答案

尝试一下:

function preventClick(buttonID) {
    $('#'+buttonID).data('events').saved_click = $('#'+buttonID).data('events').click;
    $('#'+buttonID).data('events').click = null;
}

function allowClick(buttonID) {
    $('#'+buttonID).data('events').click = $('#'+buttonID).data('events').saved_click;
}

而已!

jsFiddle示例:http://jsfiddle.net/cec6z/9/

07-24 18:03