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