注釋的地方有錯嗎?怎么輸入后點擊按鈕沒有用呢?不輸卻可以實現顯示隱藏功能,是為什么呢?
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
? ? <head>
? ? ? ? <title>toggle()方法綁定多個函數</title>
? ? ? ? <script src="http://libs.baidu.com/jquery/1.8.2/jquery.js" type="text/javascript"></script>
? ? ? ? <link href="style.css" rel="stylesheet" type="text/css" />
? ? </head>
? ? <body>
? ? ? ? <h3>toggle()方法綁定多個函數</h3>
? ? ? ? <input id="btntest" type="button" value="點一下我" />
? ? ? ? <div>我是動態顯示的</div>
? ? ? ??
? ? ? ? <script type="text/javascript">
? ? ? ? ? ? $(function () {
? ? ? ? ? ? ? ? $("#btntest").bind("click", function () {
? ? ? ? ? ? ? ? ? ? $("div").toggle(
? ? ? ? ? ? ? ? ? ? ? ? /*function (){
? ? ? ? ? ? ? ? ? ? ? ? ? ? $(this).hide();
? ? ? ? ? ? ? ? ? ? ? ? },
? ? ? ? ? ? ? ? ? ? ? ? function (){
? ? ? ? ? ? ? ? ? ? ? ? ? ? $(this).show();
? ? ? ? ? ? ? ? ? ? ? ? }*/
? ? ? ? ? ? ? ? ? ? ? ? )
? ? ? ? ? ? ? ? })
? ? ? ? ? ? });
? ? ? ? </script>
? ? </body>
</html>
2016-06-28
.toggle這個函數本身就集成了.show和.hide,再加反而是畫蛇添足。