问题描述
在大多数浏览器中,<input type="submit">
似乎将[spacebar]和[enter]都视为单击,但是<a>
链接仅将[enter]视为单击.
It looks like in most browsers, an <input type="submit">
treats both [spacebar] and [enter] as a click, but an <a>
link only treats [enter] as a click.
我的应用程序使用了许多链接,这些链接的格式设置为模拟按钮,因此习惯于使用Tab键单击按钮并按[空格键]的用户会感到沮丧.
My app uses a number of links formatted to simulate buttons, so a user that is accustomed to tabbing to a button and pressing [spacebar] will be frustrated.
这部分jQuery解决了这个问题:
This bit of jQuery solves the problem:
$("a.Button").die("keypress").live("keypress", function(e) {
if (e.which == 32) {
$(this).trigger("click");
e.preventDefault();
}
});
我的问题:是否有理由不这样做?我有点不愿意在这样的基本内容上覆盖浏览器的默认行为,但是由于我已经在滥用链接标签,使其看起来像一个按钮,因此至少我不会违反用户的期望.进一步.
My question: Is there a reason not to do this? I'm a little reluctant to override the browser's default behavior on something as basic as this, but since I'm already abusing the link tag to make it look like a button, at least this way I'm not violating the user's expectations any further.
推荐答案
我认为要维护的最重要标准不是浏览器的行为,而是用户的预期响应.
I think the most important standard to maintain is not the browser's behaviour, but rather the user's expected response.
如果通过将链接显示为按钮来覆盖链接的显示,则用户必须能够像对待真正的按钮一样正确地对待这些按钮",否则,您将会迷惑并激怒花了多年时间的用户具有这种学习"行为.
If you have overriden the display of links by turning them into buttons, the user must be able to treat those "buttons" exactly as they would if it were a real button, otherwise you will confuse and irritate users who have spent years with this "learnt" behaviour.
这篇关于jQuery-在带有空格键的链接上触发点击事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!