如何使用Javascript制作一个仅在5秒后才会出现的按钮?

如何使用Javascript制作一个仅在5秒后才会出现的按钮?,javascript,html,Javascript,Html,标题几乎说明了这一切:我需要帮助制作一个只在页面加载5秒后出现的按钮 这是我正在使用的代码: <html> <body onload="setTimeout(showStuff, 5000)"> <br><br><br><br><br><br><br><br><

标题几乎说明了这一切:我需要帮助制作一个只在页面加载5秒后出现的按钮

这是我正在使用的代码:

                <html>
                <body onload="setTimeout(showStuff, 5000)">

                        <br><br><br><br><br><br><br><br><br><br><br><br><br>        
                        <div class=login align=center>
                        <font size=13 face=helvetica> You're doing that too much. </font><br> <br> <br>
                        <font size=5 face=helvetica>
                        You have entered the wrong username/password too many times <br>
                        <br><br>
                        <br><br>
                        Click "OK" to go back to the log-in page <br> <br>
                        <p id="Button"><input type=submit onclick="myFunction()" id="Button" value="OK"> </p>

                        <script>
                        document.getElementById("Button").style.visibility = "hidden";

                        function showStuff(Button){
                        document.getElementById("Button").style.display = "inline";}

                        function myFunction() {
                            window.location = "project.html"}


                        </script>
            </div> </font>
                </body>
            </html>














你做得太多了


您多次输入错误的用户名/密码




单击“确定”返回登录页面

document.getElementById(“按钮”).style.visibility=“隐藏”; 函数showStuff(按钮){ document.getElementById(“按钮”).style.display=“inline”} 函数myFunction(){ window.location=“project.html”}
使用jquery,您可以在div中设置按钮,例如
按钮,并设置显示时间

setTimeout(function(){
   $('#div_id').show();// or fade, css display however you'd like.
}, 5000);`
或使用Javascript:

function showItbutton() {
  document.getElementById("div_id").style.visibility = "visible";
}
setTimeout("showItbutton()", 5000); // after 5 secs

使用jquery,您可以在div中设置按钮,比如
按钮,并设置显示时间

setTimeout(function(){
   $('#div_id').show();// or fade, css display however you'd like.
}, 5000);`
或使用Javascript:

function showItbutton() {
  document.getElementById("div_id").style.visibility = "visible";
}
setTimeout("showItbutton()", 5000); // after 5 secs

这可能就是您需要的


按钮
document.getElementById(“某些按钮”).style.display=“无”;
函数showStuff(){
document.getElementById(“某些按钮”).style.display=“inline”;
}
函数myFunction(){
window.location=“project.html”
}
设置超时(showStuff,5000);

这可能就是您需要的


按钮
document.getElementById(“某些按钮”).style.display=“无”;
函数showStuff(){
document.getElementById(“某些按钮”).style.display=“inline”;
}
函数myFunction(){
window.location=“project.html”
}
设置超时(showStuff,5000);

函数showStuff(){//不需要参数
document.getElementById(“按钮”).style.display=“inline”;
}   
函数定义应在函数调用之前 在函数showstuff中,不需要参数。在settimeout中使用函数()以正确执行。如果没有,它将立即执行。


函数showStuff(){//不需要参数
document.getElementById(“按钮”).style.display=“inline”;
}   
函数定义应在函数调用之前 在函数showstuff中,不需要参数。在settimeout中使用函数()以正确执行。如果没有,它将立即执行。

setTimeout()
接收毫秒,而不是秒。 所以它对你有用

JS:

HTML:

按钮
setTimeout()
接收毫秒,而不是秒。 所以它对你有用

JS:

HTML:

按钮

你应该知道的事情
*html元素

*混合使用Javascript代码是不好的做法。
*不要复制html元素ID,(感谢Calvin Nunes)

如何修复代码
*正确关闭第二个
元素并删除按钮不必要的id。
*如果使用
display='inline'
,则要隐藏元素,请使用
display='none'

工作代码

            <html>
            <body onload="setTimeout(showStuff, 5000)">

                    <br><br><br><br><br><br><br><br><br><br><br><br><br>        
                    <div class=login align=center>
                    <font size=13 face=helvetica> You're doing that too much. </font><br> <br> <br>
                    <font size=5 face=helvetica>
                    You have entered the wrong username/password too many times <br>
                    <br><br>
                    <br><br>
                    Click "OK" to go back to the log-in page <br> <br> 
                    </font>
                    <p id="Button">
                       <input type=submit onclick="myFunction()" value="OK"> </p>


              <script>

                    document.getElementById("Button").style.display= "none";

                    function showStuff(){
                        document.getElementById("Button").style.display = "inline";
                    }

                    function myFunction() {
                        window.location = "project.html"
                    }


                    </script>
            </body>
        </html>














你做得太多了


您多次输入错误的用户名/密码




单击“确定”返回登录页面

document.getElementById(“按钮”).style.display=“无”; 函数showStuff(){ document.getElementById(“按钮”).style.display=“inline”; } 函数myFunction(){ window.location=“project.html” }
你应该知道的事情
*html元素

*混合使用Javascript代码是不好的做法。
*不要复制html元素ID,(感谢Calvin Nunes)

如何修复代码
*正确关闭第二个
元素并删除按钮不必要的id。
*如果使用
display='inline'
,则要隐藏元素,请使用
display='none'

工作代码

            <html>
            <body onload="setTimeout(showStuff, 5000)">

                    <br><br><br><br><br><br><br><br><br><br><br><br><br>        
                    <div class=login align=center>
                    <font size=13 face=helvetica> You're doing that too much. </font><br> <br> <br>
                    <font size=5 face=helvetica>
                    You have entered the wrong username/password too many times <br>
                    <br><br>
                    <br><br>
                    Click "OK" to go back to the log-in page <br> <br> 
                    </font>
                    <p id="Button">
                       <input type=submit onclick="myFunction()" value="OK"> </p>


              <script>

                    document.getElementById("Button").style.display= "none";

                    function showStuff(){
                        document.getElementById("Button").style.display = "inline";
                    }

                    function myFunction() {
                        window.location = "project.html"
                    }


                    </script>
            </body>
        </html>














你做得太多了


您多次输入错误的用户名/密码




单击“确定”返回登录页面

document.getElementById(“按钮”).style.display=“无”; 函数showStuff(){ document.getElementById(“按钮”).style.display=“inl
            <html>
            <body onload="setTimeout(showStuff, 5000)">

                    <br><br><br><br><br><br><br><br><br><br><br><br><br>        
                    <div class=login align=center>
                    <font size=13 face=helvetica> You're doing that too much. </font><br> <br> <br>
                    <font size=5 face=helvetica>
                    You have entered the wrong username/password too many times <br>
                    <br><br>
                    <br><br>
                    Click "OK" to go back to the log-in page <br> <br> 
                    </font>
                    <p id="Button">
                       <input type=submit onclick="myFunction()" value="OK"> </p>


              <script>

                    document.getElementById("Button").style.display= "none";

                    function showStuff(){
                        document.getElementById("Button").style.display = "inline";
                    }

                    function myFunction() {
                        window.location = "project.html"
                    }


                    </script>
            </body>
        </html>
<script>
    window.addEventListener('DOMContentLoaded', () => {
        setTimeout(() => {
            // Assuming button has id 'myButton'.
            document.querySelector('#myButton').style.display = 'none';
        }, 5000);
    });
</script>