我正在尝试显示禁用按钮的工具提示。我不确定 jquery 事件是否会针对禁用元素触发,但我正在尝试检查是否可以显示禁用项目的工具提示。我的例子是here http://jsfiddle.net/jkLzuh0o/1/
<p>Your age:
<input id="age" title="We ask for your age only for statistical purposes.">
</p>
<p>
<input type="button" title="This a test enabled button." value="hover me please">
</p>
<p>
<input type="button" disabled="disabled" title="This a test disabled button." value="hover me please"> </p>
$(function () {
$(document).tooltip({
position: {
my: "center bottom-20",
at: "center top",
using: function (position, feedback) {
$(this).css(position);
$("<div>")
.addClass("arrow")
.addClass(feedback.vertical)
.addClass(feedback.horizontal)
.appendTo(this);
}
}
});
});
看来不能保证它能正常工作。
请参阅文档(http://api.jqueryui.com/tooltip/ http://api.jqueryui.com/tooltip/):
一般来说,禁用的元素不会触发任何 DOM 事件。因此,不可能正确控制禁用元素的工具提示,因为我们需要监听事件来确定何时显示和隐藏工具提示。因此,jQuery UI 不保证对附加到禁用元素的工具提示提供任何级别的支持。不幸的是,这意味着如果您需要禁用元素上的工具提示,您最终可能会得到本机工具提示和 jQuery UI 工具提示的混合体。
EDIT:解决此问题的一种方法是将按钮设置为disabled
,对其进行样式设置,使其看起来像是已禁用。如果它是一个简单的按钮,那么这就是你所要做的,如果它是一个submit
按钮,您还必须阻止它提交表单。
EDIT #2:我尝试了上述解决方法,结果显示opacity:0.5
几乎完成了这项工作(来源:tjvantoll.com http://tjvantoll.com/2012/03/17/Styling-Disabled-Form-Fields/):
.disabled-button {
opacity: 0.5;
}
这是您更新的小提琴:http://jsfiddle.net/jkLzuh0o/3/ http://jsfiddle.net/jkLzuh0o/3/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)