gpt4 book ai didi

jquery - 为什么 jQuery 删除了 .toggle() 方法?

转载 作者:行者123 更新时间:2023-12-01 01:14:44 25 4
gpt4 key购买 nike

.toggle( handler, handler [, handler ] )

我相信这个API非常方便。但为什么 jQuery 1.9 删除了它?

最佳答案

根据ticket # 11786,它在 1.8 中已被弃用。 。后来在 1.9 中被删除。

基本上,该票包含真正的原因,例如:

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.

关于jquery - 为什么 jQuery 删除了 .toggle() 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25052129/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com