Firefox不会在禁用的字段上显示工具提示。
以下内容在IE / Chrome / Safari中显示工具提示,但在Firefox中不显示:
<input type="text" disabled="disabled" title="tooltip text."/>
为什么Firefox不会在禁用的字段上显示工具提示?有没有解决办法?
Firefox不会在禁用的字段上显示工具提示。
以下内容在IE / Chrome / Safari中显示工具提示,但在Firefox中不显示:
<input type="text" disabled="disabled" title="tooltip text."/>
为什么Firefox不会在禁用的字段上显示工具提示?有没有解决办法?
我猜你正在使用一些像bootstrap这样的框架。如果是这样,它会在“禁用”元素上添加pointer-events: none
,因此所有鼠标事件都会被忽略。
.btn[disabled] {
pointer-events: auto !important;
}
可以解决这个问题。
if ($.browser.mozilla) {
$(function() {
$('input[disabled][title]')
.removeAttr('disabled')
.addClass('disabled')
.click(function() {return false})
})
}
我曾经遇到过类似的问题,但是我使用了jQuery和一些小的CSS类来解决它。你需要创建两个新的span元素和一个CSS类,如下所示:
只需将它们添加到通用的JS和CSS文件中,这些文件在整个应用程序或网站中都会使用。
.DisabledButtonToolTipSpan
{
position :absolute;
z-index :1010101010;
display :block;
width :100%;
height :100%;
top :0;
}
$(window).load(function() {
if ($.browser.mozilla) {
$("input").each(function() {
if ((this.type == "button" || this.type == "submit") && this.disabled) {
var wrapperSpan = $("<span>");
wrapperSpan.css({ position: "relative" });
$(this).wrap(wrapperSpan);
var span = $("<span>");
span.attr({
"title": this.title,
"class": "DisabledButtonToolTipSpan"
});
$(this).parent().append(span);
}
});
}
});
z-indexing 可以这样实现:
.btnTip
{
position: absolute;
left: 0%;
right: 0%;
z-index: 100;
width: 50px;
/*background-color: red;*/
height: 17px;
}
(…)
<div style="background-color: gray; width: 400px;">
Set width of the tip-span to the same as the button width.
<div style="text-align: center;">
<span style="position:relative;">
<span class="btnTip" title="MyToolTip"> </span>
<input type="button" name="" disabled="disabled" value="Save" style="width: 50px;height:17px;" />
</span>
</div>
左右可以帮助将主机定位在禁用元素之上。 层叠顺序定义了你要把一个元素放在哪种层级中。
层叠顺序的数字越高,它就会被放置得越“靠前”。
主机和/或禁用元素的层叠顺序应该动态设置。
当禁用元素被禁用时,你希望提示框主机处于最顶部,反之亦然——至少如果你想在元素(按钮)未被禁用时能够单击它。