jQuery:切换不起作用,有帮助吗?
我正在使用 jQuery 的切换功能,由于某种原因不起作用,这就是我所拥有的:
$(document).ready(function(){
var flip = 1;
$("#tg1").click(function () {
$("#tg1-contenido").toggle( flip++ % 2 == 0 );
});
}
我不知道我做错了什么,任何帮助将不胜感激。谢谢!
I am using the toggle function from jQuery and for some reason is not working, this is what I have:
$(document).ready(function(){
var flip = 1;
$("#tg1").click(function () {
$("#tg1-contenido").toggle( flip++ % 2 == 0 );
});
}
I don't know what I am doing wrong, any help would be greatly appreciated. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您希望每次单击都可以切换其可见性,在这种情况下您可以使用
.toggle( )
不带参数,如下所示:如果显示则隐藏它,如果隐藏则显示它。
另外,我假设您的代码被切断,但请确保您正确关闭
document.ready
包装器,最后一行仅包含}< /code> 应该是
});
。It looks like you want every other click to toggle it's visibility, in which case you can just use
.toggle()
without parameters, like this:This will hide it if it's shown, and show it if it's hidden.
Also, I'm assuming your code got cut off, but make sure you're closing your
document.ready
wrapper correctly, that last line with only}
should be a});
.