Firefox 中禁用元素的标题属性
我正在构建一个非常动态的基于 Web 的应用程序,使用大量 Javascript 来处理用户事件。我正在让东西变得更有用,但遇到了一个我以前从未遇到过的问题。
我正在使用 jQuery,所以请在您的答案中考虑到这一点。提前致谢。
我有一组按钮元素定义为:
<input type="button" title="My 'useful' text here." disabled="disabled" />
我有这些按钮,其默认样式为:
div#option_buttons input {
cursor: help;
}
然后,使用 jQuery 我在选择框上运行类似这样的单击事件:
window.current_column = '';
$('select.report_option_columns').live('click', function() {
var column = $(this).val();
if ( column == window.current_column ) {
// clear our our previous selections
window.current_column = '';
// make this option no longer selected
$(this).val('');
$('div#option_buttons input').attr('disabled','disabled');
$('div#option_buttons input').attr(
'title',
'You must select a column from this list.'
);
$('div#option_buttons input').css('cursor', 'help');
} else {
window.current_column = column;
$('div#option_buttons input').attr('disabled','');
$('div#option_buttons input').attr(
'title',
'Add this option for the column "' + column + '"'
);
$('div#option_buttons input').css('cursor', 'default');
}
});
因此,如您所见,当一列是在选择框中选择(此处未显示),我希望启用该按钮并像按钮一样运行(使用我自己的单击事件)。但是,当未选择列(包括默认加载)时,我希望禁用该按钮。我的可用性开发人员希望为用户提供微妙的上下文线索,让他们知道如何通过标题属性的本机呈现作为轻量级工具提示来启用按钮。我已经在应用程序的其他区域这样做了(这是一个疯狂的项目),我们的可用性测试表明,用户至少能够认识到,当光标更改为“帮助”时,他们可以将鼠标悬停在元素并获取有关正在发生的事情的一些信息。
但这是我第一次尝试使用表单元素。显然,当我在元素中放置disabled =“disabled”时,它完全忽略标题属性并且永远不会显示工具提示。
现在,我知道我有几个选择(至少是我能想到的):
- 编写我自己的自定义工具提示插件,该插件更加强大。
- 不要“禁用”该元素,而是将其样式设置为禁用。这是我最倾向于的选择(就开发的容易程度而言),但我讨厌这样做。
- 使按钮保持启用状态,但不处理单击事件。我不太喜欢这个选项,因为我喜欢让事物保持逻辑上应有的原生风格。禁用按钮“感觉”最正确,并且禁用按钮的外观可以立即识别为禁用按钮。
那么,说了这么多,我是不是错过了什么?有没有什么简单的事情是我可以做但我没有想到的?谷歌搜索在这个主题上让我失败了,所以我想我应该把这个扔到 StackOverflow 上以获得一些新的视角。
**编辑**
我刚刚发现了关于同一主题的另一个 StackOverflow 问题,尽管那个人使用了一组非常不同的术语来描述他的问题(可能是我没有找到它的原因)。
问题的网址是: Firefox 在禁用时不显示工具提示输入字段
该问题的两个答案都很好,尽管我想看看是否有人有其他建议。也许有更 jQuery 特定的东西?再次感谢。
I am building a very dynamic web-based application using a lot of Javascript to handle user events. I am in the process of making things a little more usable and came across a problem that I've never had before.
I am using jQuery, so factor that in to your answers. Thanks in advance.
I have a set of button elements defined as:
<input type="button" title="My 'useful' text here." disabled="disabled" />
I have these buttons with a default style of:
div#option_buttons input {
cursor: help;
}
Then, using jQuery I run something like this as a click-event on a select box:
window.current_column = '';
$('select.report_option_columns').live('click', function() {
var column = $(this).val();
if ( column == window.current_column ) {
// clear our our previous selections
window.current_column = '';
// make this option no longer selected
$(this).val('');
$('div#option_buttons input').attr('disabled','disabled');
$('div#option_buttons input').attr(
'title',
'You must select a column from this list.'
);
$('div#option_buttons input').css('cursor', 'help');
} else {
window.current_column = column;
$('div#option_buttons input').attr('disabled','');
$('div#option_buttons input').attr(
'title',
'Add this option for the column "' + column + '"'
);
$('div#option_buttons input').css('cursor', 'default');
}
});
So, as you can see, when a column is selected in the select box (not shown here), I want the button to be enabled and behave like a button would (with my own click-events). But when a column is not selected (including the default load), I want the button disabled. The usability developer in me wanted to give the users subtle contextual clues as to what they can do to enable the button through the native rendering of the title attribute as a lightweight tooltip. I do this already in other areas of the application (this is a crazy beast of a project) and our usability tests have shown that the users are at least capable of recognizing that when the cursor changes to "help" that they can hover over the element and get some information about what is going on.
But this is the first time I've ever tried this with a form element. Apparently when I put disabled="disabled" in the element, it completely ignores the title attribute and will never display the tool tip.
Now, I know I have a few options (at least the ones I could think of):
- Write my own custom tool tip plug-in that is a little bit more robust.
- Don't "disable" the element, but style it as disabled. This was the option I was leaning on the most (in terms of ease to develop) but I hate having to do this.
- Leave the button as enabled but don't process the click event. I don't like this option as much because I like to leave things natively styled as they should logically be. A disabled button "feels" the most correct and the look of a disabled button is instantly recognizable as a disabled button.
So, with all that said, am I missing something? Is there something easy that I can do that I just haven't thought of? Google searches have failed me on this topic, so I thought I'd toss this out on StackOverflow to get some fresh eyes on this.
**Edit**
I just found another StackOverflow question on this same topic, though that person used a very different set of terms describing his problem (probably why I didn't find it).
The url to the question is: Firefox does not show tooltips on disabled input fields
Both of the answers on that question are pretty good, though I'd like to see if anyone has any other suggestions. Maybe something more jQuery specific? Thanks again.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我遇到了类似的问题,我只是将禁用的元素包围在另一个元素中并与该 div 交互,我使用tipTip 显示禁用复选框的工具提示
I had a similar problem and I just surrounded the disabled element in another element and interacted with that div, i was using tipTip to show tooltip for disabled checkbox
有几个非常强大的验证插件。您可以在 jQuery 插件区域找到它们。
我碰巧喜欢并且现在很流行的另一个选择是使用“Tipsy”插件。你可以加一点“?”图标位于文本字段的右侧,人们可以将鼠标悬停在它们上方以获得“类似 facebook 的”工具提示。这个插件非常犀利,我强烈推荐它。
祝你好运!
There are several validation plugins that are very robust. You can find them in the jQuery plugins area.
Another option for you though which I happen to love and tends to be trending now adays is using the "Tipsy" plugin. You can put little '?' icons to the right of your text fields and people can mouse over them to get a "facebook-like" tool tip. This plugin is very sharp and I highly recommend it.
Good luck!
我还没有测试这是否可以解决缺少标题的问题,但您也可以使用 jquery 禁用按钮
$(document).ready()
问候,
竖琴
I haven't tested whether or not that solves the problem with the missing title, but you could also disable the button(s) using jquery on
$(document).ready()
regards,
harpax
如果这没有完全破坏您的设计,您可以将按钮替换为“span”、“p”...带有“我的‘有用’文本在这里”的标签。
仅当用户做出正确的动作时才将其与按钮交换。
If that doesn't break your design totally, you can replace your button by a "span", "p",... tag with "My 'useful' text here."
And swap it with the button only when the user makes the correct move.