實現方法:1、用click()給按鈕元素綁定點擊事件,并設置處理函數,語法“$("button").click(function(){…});”;2、在處理函數中,用hide()隱藏該按鈕元素,語法“$(this).hide();”。

本教程操作環境:windows7系統、jquery1.10.2版本、Dell G3電腦。
jquery實現點擊按鈕消失的方法:
實現方法:
-
用click()給按鈕元素綁定點擊事件,并設置處理函數
-
在處理函數中,用hide()隱藏該按鈕元素
實現代碼:
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <script src="js/jquery-1.10.2.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $("button").click(function() { $(this).hide(); }); }); </script> </head> <body> <button>點擊按鈕,點擊后消失</button> </body> </html>

hide()n內可以出入表示秒數的數字,規定隱藏效果的速度。
$(this).hide(1000);

說明:
hide() 方法隱藏被選元素
語法:
$(selector).hide(speed,easing,callback)
站長資訊網