Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在jQuery中,是否让所有超链接在鼠标按下时执行单击操作?_Javascript_Jquery_Html - Fatal编程技术网

Javascript 在jQuery中,是否让所有超链接在鼠标按下时执行单击操作?

Javascript 在jQuery中,是否让所有超链接在鼠标按下时执行单击操作?,javascript,jquery,html,Javascript,Jquery,Html,我想更改web应用程序中的标准浏览器行为,其中鼠标向下单击会导致在按钮释放之前发生单击操作。我想在一个应用程序中的所有超链接这一点。 在jQuery中有没有一种简单的方法来实现这一点? 我不是在寻找一个解决方案,改变每个环节个别。它应该是一个全局事件处理程序,在当前和将来的链接中工作 示例: 在Yahoo Mail中,只要你点击一个标签,该标签就会得到关注。它发生在按钮松开之前 对于您需要的超链接,需要模拟这种行为 如果我正确地理解了您,并且您希望覆盖默认链接行为,那么类似这样的操作应该会起作用

我想更改web应用程序中的标准浏览器行为,其中鼠标向下单击会导致在按钮释放之前发生单击操作。我想在一个应用程序中的所有超链接这一点。 在jQuery中有没有一种简单的方法来实现这一点? 我不是在寻找一个解决方案,改变每个环节个别。它应该是一个全局事件处理程序,在当前和将来的链接中工作

示例: 在Yahoo Mail中,只要你点击一个标签,该标签就会得到关注。它发生在按钮松开之前

对于您需要的超链接,需要模拟这种行为


如果我正确地理解了您,并且您希望覆盖默认链接行为,那么类似这样的操作应该会起作用:

$(function(){
    $("a").bind({ 
        click: function(e){
            e.preventDefault();
        },
        mouseenter: function(){
            window.location.href = $(this).attr("href");
        } 
    });
});

下面是一个JSFIDLE:

如果您希望它应用于页面生命周期内的所有超链接,即使是动态创建的超链接,您将需要如下内容:

$('a').live('mousedown', function(evt)
{
   // this stops the default behaviour of the event
   evt.preventDefault() 

   // This changes the location of the page to the href value of the element you clicked
   window.location.href = $(this).attr("href");

});

执行默认单击的操作是什么?执行默认单击的操作是什么?bind()不负责动态创建的链接。执行默认单击的操作是什么?我没有自定义逻辑。正确的。您希望阻止默认链接行为,然后仍然遵循该链接。有人已经回答了如何为.bind()执行此操作。我将编辑我的原始响应以包含它。它在鼠标向下移动时,而不是在悬停时。它还需要处理动态创建的链接,所以我在()或live()上使用了它。
$('a').live('mousedown', function(evt)
{
   // this stops the default behaviour of the event
   evt.preventDefault() 

   // This changes the location of the page to the href value of the element you clicked
   window.location.href = $(this).attr("href");

});
$('a').unbind('click');

$('a').bind('mousedown', function() {
  //alert('mousedown happened');
});