0

我有这两个功能可以在鼠标悬停时选择我的标签,第一个是左侧:

$(function() {
        var $items = $('#vtab>ul>li' || '#vtab2>ul>li');
        $items.mouseover(function() {
            $items.removeClass('selected');
            $(this).addClass('selected');

            var index = $items.index($(this));
            $('#vtab>div' && '#vtab2>div').hide().eq(index).show();
        }).eq(0).mouseover();
    });

这是右侧的:

 $(function() {
        var $items = $('#vtab2>ul>li');
        $items.mouseover(function() {
            $items.removeClass('selected');
            $(this).addClass('selected');

            var index = $items.index($(this));
            $('#vtab2>div').hide().eq(index).show();
        }).eq(0).mouseover();
    });

然后我有另一个淡入淡出页面的功能:

$(document).ready(function() { $("body").css("display", "none");

$("body").fadeIn(3000);

$("a.transition").click(function(event){
    event.preventDefault();
    linkLocation = this.href;
    $("body").fadeOut(2000, redirectPage);
});

function redirectPage() {
    window.location = linkLocation;
}

});

由于某种原因,第二个功能仅在页面淡入时起作用,一旦动画完成,它就会停止工作。如果我使屏幕足够小以至于我无法同时看到两个垂直列表,则第二个功能也可以使用。

有谁知道为什么会这样?我是 jQuery 新手,我真的不知道从哪里开始。

4

1 回答 1

0

我相信您的问题是错误地使用了 javascript 的布尔运算符。$('#vtab>ul>li' || '#vtab2>ul>li');

相当于:$('#vtab>ul>li')

因为 '#vtab>ul>li' 的广义布尔值是 true 并且 "||" 是它找到的第一个 true 的 javascript“或”运算符和“或”短路。

一些相关的事实:

true || true || true == true
false || true || false == false
false || 'hey there' || true == 'hey there'
'hey there' || true == 'hey there'
'hey there' && true == true
true && 'hey there' == 'hey there'
于 2012-05-21T23:50:42.040 回答