Why did jQuery remove .toggle() method? [closed]

爷,独闯天下 提交于 2019-12-22 10:49:42

问题


.toggle( handler, handler [, handler ] )

I believe this API is very handy. But why jQuery 1.9 removed it?


回答1:


It was deprecated in 1.8, as per ticket # 11786. It was later removed in 1.9.

Basically, that ticket contains the real reasons, such as:

The .toggle() method is provided for convenience. It is relatively straightforward to implement the same behavior by hand, and this can be necessary if the assumptions built into .toggle() prove limiting.

For example, .toggle() is not guaranteed to work correctly if applied twice to the same element.

Since .toggle() internally uses a click handler to do its work, we must unbind click to remove a behavior attached with .toggle(), so other click handlers can be caught in the crossfire.

The implementation also calls .preventDefault() on the event, so links will not be followed and buttons will not be clicked if .toggle() has been called on the element.



来源:https://stackoverflow.com/questions/25052129/why-did-jquery-remove-toggle-method

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!