正确使用jQuery切换? [英] The proper use of jQuery toggle?
问题描述
$('#user_button').toggle(function () {
$(".hello").addClass("active");
}, function () {
$(".hello").removeClass("active");
});
使用jQuery .toggle
回调函数向元素添加和删除类。现在根据jQuery .toggle
文档, .toggle
最初用于在所选元素的可见性状态之间切换。
The jQuery .toggle
callback function is used to add and remove classes to an element. Now according to the jQuery .toggle
documentation, .toggle
is originally used to switch between visibility states of the selected element.
我制作了一个jsfiddle演示: http:/ /jsfiddle.net/taheri/nYdng/
I've made a jsfiddle demo: http://jsfiddle.net/taheri/nYdng/
在我的示例中,这里似乎只是在回调函数之间交替,和 #user_button
本身并未切换。我在文档中错过了什么?
In my example here it seems to only alternate between call back functions, and the visibility of the #user_button
itself is not being toggled. What am i missing out in the documentation here? Can toggle be used to only alternate between functions?
推荐答案
有两种切换方法... this one和这一个。他们应该用不同的名字来避免这种混淆。
There are two toggle methods... this one and this one. They should have named them differently to avoid this confusion.
这篇关于正确使用jQuery切换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!