Stack Overflow 的各位,
我正在整理一个表单,其中包含独立的帮助文本和其他没有特定目的地的链接,但需要触发一些 jQuery 函数。
例如:
<a href="#" class="inline helpTrigger cursor">Why do we ask for this?</a>
单击或按键此链接时,文本旁边会出现一个帮助气泡。由于此 href 有一个值(“#”),我必须编写一个函数(如下所示)来阻止页面“跳转”到顶部:
$('a[href="#"]').bind('click keypress', function(event){
return false;
});
这适用于大多数浏览器,但 FireFox 在按 Tab 键切换时会卡住并获胜。 t 移过该元素。有没有更好的方法来做到这一点,或者这是一个已知的 FF 问题?
我尝试将 href 完全留空 - 但这在语义上既不正确,也不在 IE 中工作。
任何帮助将不胜感激。
谢谢
Peoples of Stack Overflow,
I'm putting together a form that has free standing help text and other links that have no specific destination, but are required to fire some jQuery function.
For example :
<a href="#" class="inline helpTrigger cursor">Why do we ask for this?</a>
On click or keypress of this link, a help bubble appears beside the text. As this href has a value ("#"), I have to write a function (as below) to stop the page from 'jumping' to the top:
$('a[href="#"]').bind('click keypress', function(event){
return false;
});
This works for most browsers, but FireFox gets stuck when tabbing through and won't moves past this element. Is there a better way of doing this, or is this a known FF issue?
I have tried leaving the href completely blank - but this is neither semantically correct, or does not work in IE.
Any help would be much appreciated.
Thanks
发布评论
评论(3)
您总是可以检查按下了哪个键并相应地继续?
You could always check which key was pressed and continue accordingly?
事实上,火狐浏览器是正确的。它不应该跳到下一个元素,因为按键事件阻止了 Tab 键。删除按键以便浏览器应用事件的默认按键处理。
Actually, Firefox is correct. It should not tab to the next element because the keypress event is blocking the Tab key. Remove the keypress in order for the browser to apply the default key processing for the event.
是否应用 event.preventDefault();解决你的问题。
does applying event.preventDefault(); solves your issue.