本文實例為大家分享了jquery中show()、hide()和toggle()用法實例,供大家參考,具體內容如下
<html><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>初識jQuery</title> <script src="http:/www.49028c.com/jquery/1.9.0/jquery.js" type="text/javascript"></script> <!--引用這個jquery庫--> <style> #test{ display:none; width:120px; height:50px; border:1px solid blue; } </style> </head> <body> <div id="test">Hello world!</div> <!--設置三個按鈕,每次點擊調用特定的函數--> <button onclick="sayHello()">點我打開!</button> <button onclick="sayGoodbye()">點我關閉!</button> <button onclick="change()">點我切換!</button> <script type="text/javascript"> function sayHello(){ $("#test").show(5000); <!--設參數5000,表示用5000ms的時間完成這個動作--> } function sayGoodbye(){ $("#test").hide(); <!--不設置,默認速度--> } function change(){ $("#test").toggle("slow"); <!--設置以slow的速度打開--> } </script> </body> </html>
效果圖:
以上就是本文的全部內容,希望對大家學習jquery程序設計有所幫助。
新聞熱點
疑難解答