单击禁用的输入或按​​钮 [英] Clicking a disabled input or button

查看:149
本文介绍了单击禁用的输入或按​​钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以点击禁用的按钮并向用户提供一些反馈?

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

HTML:

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

和JavaScript:

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');
});


推荐答案

无法捕获已禁用元素的点击。您最好的选择是对元素上的特定做出反应。

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标记:

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

JavaScript代码:

JavaScript code:

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

然后您可以使用CSS样式来模拟禁用的外观:

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

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

这是 jsFiddle 展示其用途。

这篇关于单击禁用的输入或按​​钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆