jQuery隐藏和显示效果

这里强烈推荐使用toggle()方法来切换hide()和show()方法。

语法:

$(selector).toggle(speed,callback);

可选的 speed 参数规定隐藏/显示的速度,可以取以下值:"slow"、"fast" 或毫秒。

可选的 callback 参数是 toggle() 方法完成后所执行的函数名称。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("button").click(function () {
                $("p").toggle(1600);
            })
        })
    </script>
</head>
<body>
<button type="button">transfer</button>
<p>this is a paragraph</p>
<p>this is also a paragraph</p>
<p>this is also a paragraph</p>
<p>this is also a paragraph</p>
<p>this is also a paragraph</p>
</body>
</html>

另外,可以单独使用hide()和show()方法。

猜你喜欢

转载自blog.csdn.net/weixin_41060905/article/details/82417740