简体   繁体   English

不切换时如何修复jQuery的切换function?

[英]How do I fix jQuery's toggle function when not toggling?

I have a menu that I want to toggle once the user clicks on the user's icon but right now it isn't working and I don't know why.我有一个菜单,一旦用户单击用户的图标,我想切换它,但现在它不起作用,我不知道为什么。 I would really appreciate it if anyone could help me fix it.如果有人能帮我修复它,我将不胜感激。 My code right now is:我现在的代码是:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
    $(document).ready({
        $('.account-icon').click(function({
            $('.MenujQuery').toggle('slow');
        }))
    });
</script>

<div id="user-menu">
    <img class="account-icon" src="/img/logicon.png" alt="Your Profile">
    <ul class="MenujQuery" style="display: none">
        <li class="user-item"><a href="/index.php?action=profile">Update profile</a></li>
        <li class="user-item"><a href="/index.php?action=purchases">My purchases</a></li>
        <li class="user-item"><a href="/index.php?action=logout">Log out</a></li>
    </ul>
</div>

The whole jQuery code is syntactically nonsense.整个 jQuery 代码在语法上是无意义的。 Here is how it should look like:这是它的样子:

$(document).ready(function() {
    $('.account-icon').click(function() {
        $('.MenujQuery').toggle('slow');
    })
});

It looks like you hand-copied the code from somewhere else without really understanding what it is doing, and incidentally messed up the syntax.看起来你在没有真正理解它在做什么的情况下从其他地方手工复制了代码,并且顺便弄乱了语法。 I suggest doing some tutorials first.我建议先做一些教程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM