简体   繁体   English

如何使按钮消失并在“x”秒后重新出现?

[英]How to make a button disappear and reappear after 'x' seconds?

How can I make this code;我怎样才能制作这个代码;

 <input onclick="myFunction();" alt="click">Click Me!</button>

Hide for a few seconds, then re-appear after 'x' seconds?隐藏几秒钟,然后在“x”秒后重新出现? (This button works fine if that changes anything) (如果更改了任何内容,此按钮可以正常工作)

I'd like to stick with bare HTML, but if I need Javascript that's fine.我想坚持使用裸 HTML,但如果我需要 Javascript,那很好。 No other solutions on SO work for me.没有其他关于 SO 的解决方案适合我。 Thanks.谢谢。

edit:编辑:

<link rel="stylesheet" type="text/css" href="formalign.css">
      <script type="text/javascript" src="trinit5.js"></script>
      <button class="button" id="btn" input onclick="doSingle();" alt="Summon">Summon</button>
      <img id="canvas"></img>
      <div class="element"></div>

where do i embed the part?我在哪里嵌入零件?

input tag(it is standalone tag) and a button tag(it is a paired tag) and if you want a button than you can try two things:输入标签(它是独立标签)和一个按钮标签(它是一个配对标签),如果你想要一个按钮,你可以尝试两件事:

1- assign button to the type attribute 1- 将按钮分配给 type 属性

<input type="button" id="btn" onclick="myFunction()" value="Click Me">

2-use a button tag it also has type attribute but by default button is assigned to type attribute 2-使用按钮标签,它也有 type 属性,但默认情况下按钮被分配给 type 属性

<button id="btn" onclick="myFunction()">Click Me!</button>

Here in the js i have written a function JS:在 js 中,我写了一个函数 JS:

<script>
    function myFunction()
    {
      document.getElementById('btn').style.display ='none'; //first hide the button
      setTimeout(function(){ //using setTimeout function
      document.getElementById('btn').style.display ='inline'; //displaying the button again after 3000ms or 3 seconds
    }
    ,3000); 
    }
</script>

NOTE: The setTimeout() method calls a function or evaluates an expression after a specified number of milliseconds.注意: setTimeout() 方法在指定的毫秒数后调用函数或计算表达式。 Tip: 1000 ms = 1 second.提示:1000 毫秒 = 1 秒。 Tip: The function is only executed once提示:该函数只执行一次

Bare HTML won't do it I am afraid.裸 HTML 恐怕不行。 You'll need a timer.你需要一个计时器。 Something like this maybe?也许像这样的东西?

 <button id="btn" onclick="tempInvisible(this);">Click</button> <script> function tempInvisible(btn) { btn.style.display = 'none'; setTimeout(function() { btn.style.display = 'block'; }, 10000); } </script>


Hello my friend,你好,我的朋友,

This can be accomplished fairly easily using a setTimeout in JavaScript.这可以使用 JavaScript 中的 setTimeout 轻松完成。 I've created a code snippet below which you can use as an example.我在下面创建了一个代码片段,您可以将其用作示例。 You can change the number after the comma ( 1000 ) in the setTimeout to reflect how many thousandths of a second you want the button to have disappeared for.您可以更改 setTimeout 中逗号 ( 1000 ) 后的数字,以反映您希望按钮消失的千分之一秒。

Cheers and best of luck to you!干杯,祝你好运!

 document.getElementById("button").onclick = function(){ doSingle(); document.getElementById("button").style.visibility = "hidden" setTimeout(function(){ document.getElementById("button").style.visibility = "visible" }, 1000) }; function doSingle() { // your function };
 <button class="button" id="button" alt="Summon">Summon</button>

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

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