使用JavaScript-CSS的下拉菜单

使用JavaScript-CSS的下拉菜单,javascript,html,css,Javascript,Html,Css,我正在尝试制作一个下拉菜单,它会在点击后显示并消失 JavaScript function visible(x) { var apple = document.getElementById('pulldown'+x); if (apple.style.display = "none") { apple.style.display = "block"; } } 这很好,但是在将其添加到上述代码中之后- else { apple.sty

我正在尝试制作一个下拉菜单,它会在点击后显示并消失

JavaScript

function visible(x) {
    var apple = document.getElementById('pulldown'+x);
    if (apple.style.display = "none")
    {
        apple.style.display = "block";
    }

}
这很好,但是在将其添加到上述代码中之后-

else {
     apple.style.display = "none";
}

onclick
事件只工作一次。

在if条件中使用
=
,而不是
=

if (apple.style.display == "none")

用jquery的强大功能来实现它怎么样

首先我们有一个元素(锚定标签)作为触发器,然后第二个元素是隐藏的菜单

html


您应该使用
==
=
执行类型转换,因此
'0'==0
为真。但是,您(几乎)总是希望使用
==
,这将给出
'0'==0
是错误的。在jquery中处理这个问题怎么样?@CodeDemon如何使用jquery比这更好?
<a href="#" class="pulldowntrigger">Pull down</a>
<div class="themenu" style="display: none;">menu content here</div>
// when click the anchor tag with a class pulldowntrigger
$('.pulldowntrigger').click(function(){
// check if the class themenu is hidden
if ($(this).next('.themenu')).is(":hidden"){
// yes its hidden! then slide it down (show)
$(this).next('.themenu').slideDown();
}else{
//nah! its not, then slide it up (hide)
$(this).next('.themenu').slideUp();
}
});