Html code:
Study World
- 1111111111
2222222222
- 333333333
- 4444444444
>- 6666666666
Jquery code:
First implementation method:
$(function(){
$(".topicList h3").click(function(){
var UL = $(this).next("ul");
if(UL. css("display")=="none"){
UL.css("display","block");
}
else{
UL.css("display"," none");
}
});
});
The second implementation method:
You can use show and hide provided by Jquery to complete the display and hide effects with easing. Since the two methods are similar, you can use toggle directly to complete.
$(function(){
$(".topicList h3").toggle(function(){
$(this).next("ul").css("display", "none");
},function(){
$(this).next("ul").css("display","block");
});
} );
The fourth implementation method:
toggle If there are two parameters and both are functions, it means the first Click to execute the first function, and click the second to execute the second function.
$(function(){
$(".topicList h3").toggle(topicHandler,topicHandler);
function topicHandler(){
//You can use fadeIn, show, slideDown Complete the display of a certain container
//Use fadeOut, hide, slideUp to complete the hiding of a certain container
//So the rotation between the two can be completed through each toggle
$(this) .next("ul").toggle(1000);
}
});
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn