0

我知道我一定遗漏了分号或一些简单的东西,但是下面的代码是淡出一个段落,它确实淡入了一个名为 newtext 的 div 和一个带有 btn2 样式的按钮,它确实如此。但是,当我单击按钮时, div newtext 应该会淡出,但不会。知道代码有什么问题吗?谢谢。

$(document).ready(function(){

   setTimeout(function(){

       $("p").fadeOut();
       $("#newtext").fadeIn();

   $("btn2").click(function(){
       $("#newtext").fadeOut()
       });


   },2000);


});
4

2 回答 2

1

You are missing a class or ID selector here:

$("btn2")

Your selector should be $("#btn2") or $(".btn2"), if it is resp. a ID or a class in that element.

You might also want to move the click event attacher to outside your setTimeout. Like that it will only attach after 2 seconds. (maybe it is the behaviour you want).

于 2013-11-14T22:01:13.363 回答
1

This code: $("btn2") implies that you have an html element like so: <btn2>...</btn2>

Perhaps you meant to select a class or id?

For example: $(".btn2") for a class or $("#btn2") for an id.

于 2013-11-14T22:02:12.690 回答