Javascript 触发mousedown事件后,Jquery-hover事件消失。

Javascript 触发mousedown事件后,Jquery-hover事件消失。,javascript,jquery,Javascript,Jquery,jquery脚本有问题。使用下面的脚本加载页面。悬停事件工作正常。但是,如果mousedown事件触发,hover事件功能随后将消失,并且我不会得到任何滚动。关于为什么以及如何让悬停事件每次都启动,有什么想法吗?在IE中查看页面 // Rollover effect for sign. $("#sign").hover(function () { $("#sign").css('background', 'url(img/default/signinon.png) no-repeat 0

jquery脚本有问题。使用下面的脚本加载页面。悬停事件工作正常。但是,如果mousedown事件触发,hover事件功能随后将消失,并且我不会得到任何滚动。关于为什么以及如何让悬停事件每次都启动,有什么想法吗?在IE中查看页面

// Rollover effect for sign.
$("#sign").hover(function () {
    $("#sign").css('background', 'url(img/default/signinon.png) no-repeat 0 0');
},
function () {
    $("#sign").css('background', 'url(img/default/signin.png) no-repeat 0 0');
});


//Mousedown function... 
$(document).mousedown(function (event) {

    var $target = $(event.target);


    // A click outside of the sign in panel or a click on the sign in button when the body panel is visible, hides the display.

    if ((!$target.is('#sign') && !$target.is('#sign-in-panel') && !$target.parents().is('#sign-in-panel') && !$target.parents().is('#sign')) ||
   ($target.is('#sign') && $("#sign-in-panel").css('visibility') == 'visible')) {
        $("#sign-in-panel").css('visibility', 'hidden');
        $("#sign").css('background', 'url(img/default/signin.png) no-repeat 0 0');

    }
    else {
        // Show the panel
        $("#sign-in-panel").css('visibility', 'visible');

    }
});

只是一个建议,尝试将背景从css改为jquery

.signinClass
{
background :url(img/default/signin.png) no-repeat 0 0;
}
.signinClass:hover
{
background :url(img/default/signinon.png) no-repeat 0 0;
}

鼠标按下可能会阻止悬停事件触发。

为什么不使用click()而不是mousedown()?用click()代替mousedown()似乎会产生相同的结果。一旦第一次点击完成,悬停事件就不会触发。这里对我有用:试着把你的代码放在那里谢谢。我认为只有当css背景属性更改为新图像时,问题才会出现。JSFIDLE上的源代码不会重置背景。我注意到这行:$(“#sign”).css('background','url(img/default/sign.png)no repeat 0');在mousedown事件中,hover事件在执行后被禁用——或者至少我目前看到的情况是这样。我可以这样做,但我希望使用jquery来控制整个过程。没有重置悬停事件的方法?如果重置悬停事件的意思是切换该特定元素的类,则可以切换该元素的类。