开发者

How use mousedown/click events for disabled objects?

Considering the following, how can I enable a disabled element on click?

$("element").click(function(){
    //ena开发者_运维百科ble element
});


The best I could come up with is:

$('label').click(
    function(){
        $(this).next(':disabled').removeAttr('disabled');
    });

Since the disabled element itself doesn't, at least in Chrome 8/Ubuntu 10.10, respond to click events.

This does assume, of course, that the label precedes the disabled element, and doesnt', in its current form, check that the label corresponds to the next disabled element.

JS Fiddle demo of the above.


Edited to revise the approach, so clicking on the label affects only the relevant input:

$('label').click(
    function(){
        var relevantInput = $(this).attr('for');
        $('#' + relevantInput)
            .removeAttr('disabled');
    });

JS Fiddle demo


Dupilicate: Jquery event on a disabled input.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜