在jQuery1.9之后toggle()用法例子

jQuery 在1.9版移除toggle之后,像这样toggle(fn1,fn2,fn3)轮换着点击页面分别触发fn1,fn2,fn3函数的方法已经被废弃了。

在搜集资料之后有了如下两种方法使用:

Css和Html代码:
<style>
    .answer {
        display: none;
    }
</style>
//style样式 <body> <p id="question">什么是jQuery</p> <p class="answer">jQuery是。。。</p> </body> //html代码

方法一:

1 $(document).ready(function(){
2         $('#question').click(function () {
3             $('.answer').toggle();
4         });
5     });

方法二:

 1 $(document).ready(function () {
 2         var flag = true;
 3         $('#question').click(function () {
 4             if (flag){
 5                 $('.answer').show();
 6                 flag = false;
 7             }else {
 8                 $('.answer').hide();
 9                 flag = true;
10             }
11         });
12     });

完结^_^

资料参考来源:

  https://blog.csdn.net/qq_16467097/article/details/52398953

  https://bbs.csdn.net/topics/392006628?list=31152598

posted @ 2020-04-01 15:36  秀成  阅读(216)  评论(0编辑  收藏  举报