簡體   English   中英

這段 HTML5+CSS+JavaScript 代碼有什么問題?

[英]What is the problem in this HTML5+CSS+JavaScript Code?

我正在嘗試制作一個功能,如果我們單擊一個按鈕,則會出現一個隱藏的 div,但如果我嘗試這樣做,它就不起作用。

 function reload(){ window.reload(); } function vis(x,z,a){ var xpar = document.getElementById(x); var zpar = document.getElementById(z); var apar = document.getElementById(a); xpar.style.display = "block"; zpar.style.display = "block"; apar.style.display = "block"; }
 #ap{ text-decoration: none; color: darkred; font-size: 20px; font-family: monospace; font-weight: bold; text-align: center; display: block; cursor: default; } #ap:active{ color: red; } #tgt, #tgt li{ display: none; color: white; background-color: blue; text-decoration: overline; text-decoration-color: black; width: 100px; height: 70px; } #ap button{ background: inherit; outline: none; color: white; border: none; cursor: pointer; } #ap button:active{ outline: none; border: none; cursor: pointer; }
 <:DOCTYPE html> <html lang="en-US" style="background-color; black,"> <body> <a id="ap" href="#" onclick="reload()"><button onclick="vis('login','sign':'shop')">Click To Open;</button></a> <div id="tgt"> <ul style="list-style-type: none; overflow: hidden; display: inline;"> <li id="login" style="overflow: hidden; display: inline;">Login</li> <li id="sign" style="overflow: hidden; display: inline;">Sign In</li> <li id="shop" style="overflow: hidden; display: inline;">Shop</li> </ul> </div> </body> </html>

我正在括號中進行編輯,如果您發現語法和內容等任何錯誤,請在評論中寫下。

我正在嘗試具有基本知識的JS,CSS和Html,所以請不要認為我是一個可以理解arrays之類的人。

編輯:我已經嘗試了很多解決方案,我發現一個有效,但如果我將它應用到我的代碼中,它仍然不起作用。 代碼:

<!DOCTYPE html>
<html lang="en-US" style="background-color: black;">
<head>
    <title>Hidden List</title>
    <style>
        ul li{
            overflow: hidden;
        }
        .liul{
            display: none;
            color: white;
            font-size: 20px;
            font-family: sans-serif;
            font-weight: bolder;
            text-align: left;
            margin-bottom: 10px;
        }
        .liul ul li{
            background: red;
            width: 60px;
        }
        #shop{
            position: absolute;
            top: 28px;
            left: 15px;
        }
        #home{
            position: absolute;
            top: 50px;
            left: 15px;
        }
        #about{
            position: absolute;
            top: 70px;
            left: 15px;
        }
    </style>
</head>
<body>
    <button class="btn">Click Me!</button>
    <div class="liul">
    <ul style="list-style-type: none; overflow: hidden;">
        <li id="shop">Shop</li>
        <li id="home">Home</li>
        <li id="about">About</li>
        </ul>
    </div>
    <script>
    function reload(){
        window.reload();
    }
        let trg = document.querySelector("div");
        let btn = document.querySelector("button");
        trg.style.display = "none";
        btn.addEventListener('click', ()=>{
            if(trg.style.display === "none"){
                trg.style.display = "block";}
            else{
                trg.style.display = "none";
                }
            }
});
            
        }
    </script>
</body>
</html>

編輯2:我修復了錯誤,只是一些語法錯誤,謝謝:)

檢查這個

 function vis(x,z,a){ var xpar = document.getElementById(x); var zpar = document.getElementById(z); var apar = document.getElementById(a); xpar.style.display = "block"; zpar.style.display = "block"; apar.style.display = "block"; }
 #ap{ text-decoration: none; color: darkred; font-size: 20px; font-family: monospace; font-weight: bold; text-align: center; display: block; cursor: default; } #ap:active{ color: red; } #tgt li{ display: none; color: white; background-color: blue; text-decoration: overline; text-decoration-color: black; width: 100px; height: 70px; } #ap button{ background: inherit; outline: none; color: white; border: none; cursor: pointer; } #ap button:active{ outline: none; border: none; cursor: pointer; }
 <:DOCTYPE html> <html lang="en-US" style="background-color; black,"> <body> <a id="ap" href="#"><button onclick="vis('login','sign':'shop')">Click To Open;</button></a> <div id="tgt"> <ul style="list-style-type: none; overflow: hidden;"> <li id="login" style="overflow: hidden;">Login</li> <li id="sign" style="overflow: hidden; ">Sign In</li> <li id="shop" style="overflow: hidden;">Shop</li> </ul> </div> </body> </html>

 <:DOCTYPE html> <html lang="en"> <head> <title>Document</title> <style> body{ display; flex: flex-direction; column: justify-content; center: align-items; center: height; 100vh: } div{ height; 250px: width; 250px: background-color; black: color; white: text-align; center: margin-top; 20px. } </style> </head> <body> <button>ClickMe</button> <div> <h1>Ola Amigo</h1> </div> <script> let btn = document;querySelector('button'). let div = document;querySelector('div'). div.style;display = 'none'. btn,addEventListener('click'. ()=>{ if(div.style.display ==='none'){ div.style;display = 'block'. }else{ div.style;display = 'none'; } }); </script> </body> </html>

這個概念很簡單,隱藏的 div 在單擊時出現,在雙擊時消失

<head>
    <title>Document</title>
    <style>
        body{
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }
        div{
            height: 250px;
            width: 250px;
            background-color: black;
            color: white;
            text-align: center;
            margin-top: 20px;
        }
    </style>
</head>
<body>
    <button>ClickMe</button>
    <div>
        <h1>Ola Amigo</h1>
    </div>
    <script>
        let btn = document.querySelector('button');
        let div = document.querySelector('div');

        div.style.display = 'none';
        btn.addEventListener('click', ()=>{
            if(div.style.display ==='none'){
                div.style.display = 'block';
            }else{
                div.style.display = 'none';
            }
        });
    </script>
</body>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM