简体   繁体   English

Javascript 的新功能:弹出菜单

[英]New to Javascript: Popup Menu

I'm trying to make a website and I'm stuck now that I'm in JS territory.我正在尝试建立一个网站,但现在我被困在 JS 领域。 I am OK with HTML and CSS, but I feel like a total moron when it comes to JS.我对 HTML 和 CSS 没问题,但在谈到 JS 时,我觉得自己完全是个白痴。

Here's what I have (and I'm sure it's dead wrong) so far...到目前为止,这就是我所拥有的(而且我确信这是完全错误的)......

var clicked = getElementById('loginIcon').clicked;
function showHideLogin() {
    if (clicked) {
        getElementById('loginField').visibility = "visible";
    }
    else {
        getElementsById('loginField').visibility = "hidden";
    }
}

Please, be kind... I'm just starting to learn JS and I'm ripping my hair out and feeling like a complete idiot...拜托,善良...我刚开始学习 JS,我正在扯掉我的头发,感觉自己像个彻头彻尾的白痴...

I'm trying to make a login that only shows when an icon (png) is clicked.我正在尝试进行仅在单击图标(png)时显示的登录。 Otherwise, it's hidden.否则,它是隐藏的。

EDIT: Thanks for the replies so far.编辑:感谢到目前为止的答复。 This is how much of a noob I am: Atom says " Node is not recognized as an internal or external command" which, by Googling, I've found out means I don't have Node JS (which I have to research more to understand).这就是我的菜鸟程度:Atom 说“节点不被识别为内部或外部命令”,通过谷歌搜索,我发现这意味着我没有 Node JS(我必须研究更多才能理解)。

Thanks guys.多谢你们。 I'll let you know if it's still not working.如果它仍然不起作用,我会告诉你。

Try尝试

getElementById('loginField').style.visibility = "visible"; getElementById('loginField').style.visibility = "visible";

You're not setting the visibility correctly.您没有正确设置可见性。 It should be:它应该是:

getElementById('loginField').style.visibility = "visible";

Also, I'm not sure when showHideLogin is expected to be called, but the norm for setting an event handler is to register a function.另外,我不确定何时会调用showHideLogin ,但设置事件处理程序的规范是注册 function。 Something like:就像是:

getElementById('loginIcon').onclick = function() {
    // perhaps some conditions or other logic
   getElementById('loginField').visibility = "visible";
};

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

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