jQuery为什么要删除.toggle()方法? [英] Why did jQuery remove .toggle() method?

查看:90
本文介绍了jQuery为什么要删除.toggle()方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.toggle(handler,handler [,handler])

我相信此API非常方便.但是为什么jQuery 1.9删除了它?

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

推荐答案

根据票号11786 .后来在1.9中将​​其删除.

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:

为方便起见,提供了.toggle()方法.手动实现相同的行为是相对直接的,如果.toggle()中内置的假设证明是限制性的,则可能有必要.

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.

例如,.toggle()如果两次应用于同一元素,则不能保证其正常工作.

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

由于.toggle()在内部使用点击处理程序来完成其工作,因此我们必须取消绑定点击以删除.toggle()附带的行为,以便其他点击处理程序可能会陷入困境.

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.

该实现还会在事件上调用.preventDefault(),因此,如果在元素上调用了.toggle(),则不会跟随链接,也不会单击按钮.

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为什么要删除.toggle()方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆