hover方法的語法結構為:hover(enter,leave) hover()當鼠標移動到元素上時,會觸發第一個方法,當鼠標移開的時候會觸發第二個方法 復制代碼 <html> <head> <title>測試用</title> <script type="text/javascript" src="../jquery-1.3.2.min.js"></script> <script type="text/javascript"> window.onload=init; function init(){ $("#panel h5.head").hover(function(){ $(this).next().hide(); },function(){ $(this).next("div .content").show(); }); } </script> </head> <body> <div id="panel"> <h5 class="head">什么事jquery</h5> <div class="content"> 混蛋 </div> </div> </body> </html> 復制代碼 toggle(fn1,fn2,fn3..)這個方法是每次單擊調用下一個方法,如果方法是最后一個,那么從第一個開始 如果只有2個方法,則是互相切換效果。 復制代碼 <html> <head> <title>測試用</title> <script type="text/javascript" src="../jquery-1.3.2.min.js"></script> <script type="text/javascript"> window.onload=init; function init(){ $("#panel h5.head").toggle(function(){ $(this).addClass("highlight"); $(this).next().hide(); },function(){ $(this).removeClass("highlight"); $(this).next("div .content").show(); }); } </script> <style type="text/css"> .highlight{ background:#ff3300; } </style> </head> <body> <div id="panel"> <h5 class="head">什么事jquery</h5> <div class="content"> 混蛋 </div> </div> </body> </html>