Home > Web Front-end > JS Tutorial > jquery: Detailed explanation of how to use toggle

jquery: Detailed explanation of how to use toggle

黄舟
Release: 2017-06-26 13:28:18
Original
2796 people have browsed it

The following editor will bring you a detailed explanation of the two usages of toggle in jquery (recommended). The editor thinks it’s pretty good, so I’ll share it with you now and give it as a reference. Let’s follow the editor and take a look.

1. Bind two or more functions in the element’s click event Unlike bind where you need to add "click" at the end to bind the click trigger event, toggle itself is click triggered (and can only be triggered by click),

The following example:

<input id="btntest" type="button" value="点一下我" />
<p>我是动态显示的</p>

<script type="text/javascript">
  $(function () {
    $("#btntest")
      $("#btntest").toggle(
      function(){
        $("p").html("我变了!");
      },
      function(){
        $("p").html("我又变了!");
      });
    });
</script>
Copy after login

2. Switch the display and hide effects of elements:


<input id="btntest" type="button" value="点一下我" />
<p>我是动态显示的</p>

<script type="text/javascript">
  $(function () {
    $("#btntest").bind("click",function(){
      $("p").toggle(500);//此处的 500 是隐藏显示的延迟时间,默认为0,也可以用"slow","normal"或"fast"
                 //如果里面的值为true(toggle(true))时只能显示元素,值为false(toggle(false))时只能隐藏元素。) }) }); </script>
Copy after login

The above is the detailed content of jquery: Detailed explanation of how to use toggle. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template