jquery页面隐藏和展开之间切换

html页面:

 <p id="myp4">默认情况下,这段话是隐藏的,点击按钮以后,这段话就展开,并且按钮上的值改变</p>
    <button id="b6" >展开</button>

js页面:

 1 $(document).ready(function () {
 2     $("#b6").click(function () {
 3         $("#myp4").toggle();
 4         var top = document.getElementById("myp4");
 5         if (top.style.display == "none") {
 6             $("#b6").text("展开");
 7         } else {
 8             $("#b6").text("隐藏");
 9         }
10         
11        })
12 })

通过判断id为myp4的元素的display属性document.getElementById("myp4").style.display ,来设置按钮上的值。


原文地址:https://www.cnblogs.com/alisayuan/p/4737219.html