標籤:des http 使用 strong io for cti ar
.toggle(function, function, … )
|
link .toggle(function, function, ... ) removed
This is the "click an element to run the specified functions" signature of .toggle(). It should not be confused with the "change the visibility of an element" of .toggle() which is not deprecated. The former is being removed to reduce confusion and improve the potential for modularity in the library. The jQuery Migrate plugin can be used to restore the functionality. |
需要注意的是該.toggle()是“綁定兩個或多個處理常式,在點擊時迴圈執行”;另一個.toggle()仍然存在,它是“控制相應組件的顯示和隱藏”;中文晦澀,官方對此二方法的說明如下:
|
Categories: Deprecated > Deprecated 1.8 | Events > Mouse Events .toggle(handler(eventObject), handler(eventObject) [,handler(eventObject)])Returns:jQueryversion deprecated: 1.8, removed: 1.9
Description:Bind two or more handlers to the matched elements, to be executed on alternate clicks. |
|
Categories: Effects > Basics .toggle( [duration ] [, complete ] )Returns:jQuery
Description:Display or hide the matched elements. |
這個變化值得注意。對於刪除的這個“.toggle()”方法,官方沒有給出升級措施,但我發現一個方法名和描述都比較相似的方法“.trigger()”,不知道可不可以替代。
我用2.0.0版本執行下面版本:
$(function () {
$("h5").toggle(function () {
$(this).next("div").show();
}, function () {
$(this).next("div").hide();
});
});
想用toggle()控制div的單擊顯隱,但是這麼寫為什麼一開啟頁面,標題和div就全漸漸消失了?
因為。Jquery1.9.1中 toggle(fn1,fn2...)方法 可實現點擊一個元素來執行指定函數。此方法被刪除以減少混亂和提高潛在的模組化程度。只保留了顯示和隱藏的功能!
官網:http://api.jquery.com/toggle/
原始解決方案:全域一個counter=0 click事件中判斷counter%2==0 分別觸發不同的css,然後counter++,簡單粗暴。
或者使用狀態機器,可以看阮一峰寫的文章。