javascript - jQuery 显示隐藏菜单基础知识

标签 javascript jquery html

我正在尝试制作一个双菜单,具有点击功能和隐藏和显示基础功能,但我不明白为什么不起作用,你能帮我吗?这是我的脚本:

$(document).ready(function() {

$('#work').click(function(event){
    $(this).addClass("activado"); // add active class
    $("#other,#contacto").removeClass("activado"); // remove active class
    $("#menuother").hide();
    $("#menuwork").show();
});

$('#other').click(function(event){
    $(this).addClass("activado");
    $("#work,#contacto").removeClass("activado");
    $("#menuwork").hide();
    $("#menuother").show();
});

$('#contacto').click(function(event){
    $(this).addClass("activado");
    $("#work,#other").removeClass("activado");
    $("#menuwork").hide();
});
});

我的 html 非常基本,我认为你不需要它,脚本会自己说话。事件类正在工作,但隐藏和显示不工作。

非常感谢。

//编辑 顺便说一句,我在 css 中隐藏了菜单。

//编辑添加html

<a href="#" id="work" class="inactivo">TopMenu</a>
<a href="#" id="other" class="inactivo">TopMenu</a>
<a href="#" id="contacto" class="inactivo">TopMenu</a>

<div id="#menuwork">
<a href="#" id="SubMenu1" class="inactivo">SubMenu</a>
<a href="#" id="SubMenu2" class="inactivo">SubMenu</a>
<a href="#" id="SubMenu3" class="inactivo">SubMenu</a>
</div>

<div id="#menuother">
<a href="#" id="SubMenu4" class="inactivo">SubMenu</a>
<a href="#" id="SubMenu5" class="inactivo">SubMenu</a>
<a href="#" id="SubMenu6" class="inactivo">SubMenu</a>
</div>

最佳答案

首先,从 div 元素的 ID 中删除 #。例如:

<div id="#menuwork">

应该是:

<div id="menuwork">

关于javascript - jQuery 显示隐藏菜单基础知识,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7744583/

相关文章:

javascript - 谷歌地图 v3 缩放控件未显示

jquery - 使用 jQuery 文本字段选择全部/放置光标

javascript - 如何使用 JS 使用单选按钮更改容器边框的颜色?

Java openStream() 工作时间取决于网站代码?

jquery - 非 ascii 字符仅在 Safari 浏览器中添加表单输入

javascript - 当谷歌地图标记移动时更新mysql数据库

javascript - 比较本地 Node 模块版本与package.json版本

javascript - 错误 : attempted to update component that has already been unmounted (or failed to mount)

javascript - 如何 grep 这个 Javascript 对象数组?

javascript - 如何在 Adob​​e Dreamweaver CS4 上使用 javascript