jQuery:切换不起作用,有帮助吗?

发布于 2024-09-26 21:01:59 字数 286 浏览 0 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伪心 2024-10-03 21:01:59

看起来您希望每次单击都可以切换其可见性,在这种情况下您可以使用 .toggle( ) 不带参数,如下所示:

$("#tg1").click(function () {
  $("#tg1-contenido").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:

$("#tg1").click(function () {
  $("#tg1-contenido").toggle();
});

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 });.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文