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

问题描述

正如我现在所知道的那样.toggle()方法在jQuery 1.9版中已被弃用.可以,但是我很熟悉.解决方案是导入最新的jQuery迁移插件.

As I know now .toggle() method is deprecated in jQuery version 1.9. It is ok, but I was familiar with it. The solution was to import the latest jQuery migrate plugin.

在官方jQuery API文档上,我可以看到.toggle()方法的描述中有一条注释:

On the official jQuery API documentation I can see that there is a note in the description of the .toggle() method:

是的,我可以改用.toggleClass(),但是在这种情况下,它只能在两个类之间切换.

Yes, I may use .toggleClass() instead, but in this case it only switches between two classes.

此外,为什么不建议使用?

Also, why is it not recommended to use?

推荐答案

不推荐使用.改用.toggleClass()"注释与所提供的示例有关,该示例使用.toggle()切换类,不是一般注释关于.toggle().

The "Not recommended. Use .toggleClass() instead" comment is about the provided example, which toggles a class using .toggle(), it's not a general comment about .toggle().

文档还说明了不建议使用的原因:

The docs also state why it is not recommended to use:

在此处查看更多讨论

这篇关于jQuery toggle()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 04:04
查看更多