双击打开链接 [英] Make a link open on double click
问题描述
如何制作超链接< a>链接< / a>
双击链接:i:e链接应该在双击时打开,单击应该不做任何事情。
好的,那么您可以执行此操作:
HTML:
< a id ='golink'href ='gosomewhere.html'>去某个地方< / a>
使用jQuery的JavaScript:
jQuery(function($){
$('#golink')。click(function(){
return false;
})。dblclick(function ){
window.location = this.href;
return false;
});
});
(它不一定是一个ID;你可以用一个类或其他任何可以让你做到的事情形成一个jQuery可以处理的选择器来挂钩)。
如果用户禁用JavaScript,链接将正常工作。爬行者通常会找到链接,等等。如果用户启用了JavaScript,事件处理程序就会被连接起来,并且需要双击。
键盘导航,然后,你必须处理:
pre $ j $ c $ jQuery(function($){
$( '#golink')。click(function(){
return false;
))。dblclick(function(){
window.location = this.href;
return false ;
})。keydown(function(event){
switch(event.which){
case 13://输入
case 32://空格
window.location = this.href;
return false;
}
});
});
我无法想象这对辅助功能有好处,我敢打赌,还有其他的东西不能满足上述要求。以下是所有内容:
但是我强烈建议不要这样做,如果没有 真的很好 用例。
How to make hyper link <a>Link</a>
a double click link: i:e link should open on double click and single click should do nothing.
Okay, so, you can do this:
HTML:
<a id='golink' href='gosomewhere.html'>Go Somewhere</a>
JavaScript using jQuery:
jQuery(function($) {
$('#golink').click(function() {
return false;
}).dblclick(function() {
window.location = this.href;
return false;
});
});
(It doesn't have to be an ID; you can do this with a class or anything else that lets you form a selector that jQuery can process to hook things up.)
If the user has JavaScript disabled, the link will work normally. Crawlers will find the link normally, etc. If a user has JavaScript enabled, the event handlers will get hooked up and it will require a double click.
The above blows away keyboard navigation, though, so then you have to handle that:
jQuery(function($) {
$('#golink').click(function() {
return false;
}).dblclick(function() {
window.location = this.href;
return false;
}).keydown(function(event) {
switch (event.which) {
case 13: // Enter
case 32: // Space
window.location = this.href;
return false;
}
});
});
I can't imagine this is good for accessibility, and I bet there are other things not catered for above. Which all feeds into:
But I'd strongly recommend against doing it without a really good use case.
这篇关于双击打开链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!