简体   繁体   English

jQuery的切换菜单不起作用

[英]jquery toggle menu doesn't work

Im trying to achieve a css jquery toggle menu, but it doesn't function these are the codes im using 我试图实现一个css jquery切换菜单,但它不起作用,这些是我正在使用的代码

CSS: CSS:

#submenu  ul{
display:none;
} 

#submenu ul li {
text-align: right;
display: block;
}

.bnt {
display: block;
color:#fff;
font-size: 15px;
text-align: right;
cursor: pointer;
}

.bnt:before {
content:"menu";
}   

and the JS 和JS

<script>
$('.bnt').click(function () {
   $('#submenu ul').toggle();
})
</script>

is there any error on these codes? 这些代码有什么错误吗?

The problem is because you need to wrap your code in ready handler and Make sure you have loaded the jQuery before your Script start or in the <head>....</head> section: 问题是因为您需要将代码包装在就绪处理程序中,并确保在脚本启动之前或<head>....</head>部分中已加载了jQuery:

$(document).ready(function() {
    $('.bnt').click(function () {
      $('#submenu ul').toggle();
    });
});

WORKING DEMO 工作演示

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

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