这段代码有什么问题? (Jquery的)

时间:2015-03-27 22:45:39

标签: javascript jquery

这可能是一个愚蠢的错误,但我的大脑今天不起作用。

我有一个按钮和两个<h1>元素。当你按下按钮时它们会生成动画,我希望当你将鼠标悬停在文本上时它会消失。

按下按钮时,按钮也会自动隐藏。

这是我的代码:

$(document).ready(function(){
    $("#button1").click(function() {
        $('#text1').animate({right: '700px'}, 'slow');
        $('#text2').animate({right: '900px'}, 'slow');
        $(this).toggle();
    });

    $('#text1', '#text2').mouseover(function(){
        $('#text1', '#text2').fadeTo('slow', 0);
    });
});

1 个答案:

答案 0 :(得分:3)

只是选择器。

$('#text1, #text2').mouseover(function(){
    $('#text1, #text2').fadeTo('slow', 0);
});

$('#text1', '#text2')实际上使用了$( selector [, context ] )表单 - 解释here - ,这意味着#text1必须位于#text2内。这可能不是你想要的。

相关问题