.toggle( handler(eventObject), handler(eventObject) [, handler(eventObject) ] )
handler(eventObject)
Type: Function()
A function to execute every even time the element is clicked.
A function to execute every odd time the element is clicked.
Additional handlers to cycle through after clicks.
<code>$("td").toggle(</code>
<code>function () {</code>
<code>$(this).addClass("selected");</code>
<code>},</code>
<code>$(this).removeClass("selected");</code>
<code>}</code>
<code><code>);</code></code>Toggle a style on table cells. (Not recommended. Use .toggleClass() instead.):
關閉/顯示側邊欄用到了這個函數:
<li id="close-sidebar"><a>幹掉側邊欄</a></li> /* 可加在導航ul标簽中 */
$('#close-sidebar a').toggle(function(){ //選中id="close-sidebar"内的a标簽的内容,即“幹掉側邊欄”
$(this).text("顯示側邊欄"); //點選此中内容後改變成“顯示側邊欄”
$('#sidebar').hide(); //隐藏id="sidebar"的内容,即“側邊欄”
$('#content').animate({width: "960px"}, 1000); //讓id="content",即主體部分的寬度伸長至960px,時間為1000毫秒
},function(){
$(this).text("關閉側邊欄"); //點選此中内容後改變成“關閉側邊欄”
$('#sidebar').show(); //顯示id="sidebar"的内容,即“側邊欄”
$('#content').animate({width: "705px"}, 800); //讓id="content",即主體部分的寬度縮至705px,時間為800毫秒
});