Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
363 views
in Technique[技术] by (71.8m points)

javascript - Clicking a disabled input or button

Is it possible to click on a disabled button and provide some feedback to the user?

HTML:

<input type="button" value="click" disabled>

and JavaScript:

$('input').mousedown(function(event) {
    alert('CLICKED');
});

The above code is not working for me; neither is this:

$('input').live('click', function () {
    alert('CLICKED');
});
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There is no way to capture a click on disabled elements. Your best bet is to react to a specific class on the element.

HTML Markup:

<input type="button" class="disabled" value="click" />

JavaScript code:

$('input').click(function (event) {
    if ($(this).hasClass('disabled')) {
        alert('CLICKED, BUT DISABLED!!');
    } else {
        alert('Not disabled. =)');
    }
});

You could then use CSS styling to simulate a disabled look:

.disabled
{
    background-color: #DDD;
    color: #999;
}

Here's a jsFiddle demonstrating its use.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...