在Chrome中移动鼠标后,jQuery点击事件才起作用 [英] jQuery click event only working after moving the mouse in Chrome

查看:94
本文介绍了在Chrome中移动鼠标后,jQuery点击事件才起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我知道有更好的切换风格的方法,但忍受着我......



Chrome上似乎有一个小错误(但不是Firefox )'click'事件不会做任何事情,直到鼠标移动到事件之后。

  $(function(){
$('#choices something a [rel $ =。css]')。click(function(e){
e.preventDefault();
$('link.skeletor') .attr('href',$(this).attr('rel'));
});
});

所以,如果您点击链接但不移动鼠标,就没有任何反应......您是否认为这可能是Chrome的一个合法的bug或我做错了什么?

(除了奇怪的rel =使用)。

如果您试图使用带有多个js实例的缩小版或版本,则问题可能是 .click 而不是 .on('click',function(e))



要查看我想说的一个示例,请查看我的小提琴。



有关两个点击函数之间差异的完整说明,请查看


So I know there are better ways of switching styles, but bear with me...

There seems to be a small bug happening on Chrome (but not Firefox) where the 'click' event wont do anything until the mouse has moved after the event.

$(function(){
    $('#selectsomething a[rel$=".css"]').click(function(e){
        e.preventDefault();
        $('link.skeletor').attr('href', $(this).attr('rel')); 
    });
});

So if you click the link but don't move the mouse nothing happens... Do you think this may be a legitimate bug with Chrome or am I doing something wrong?

解决方案

I don't why this shouldn't work (except the strange rel="" use).

If you are trying to use a minified or a version with multiple instances of the js the problem might be the usage of .click instead of the .on('click', function(e)).

To see an example of what i trying to say, check out my Fiddle.

For a full explanation on the difference between the two click functions check this overflow

这篇关于在Chrome中移动鼠标后,jQuery点击事件才起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆