使HTML按钮在点击时消失,然后在X时间后重新出现?

时间:2013-02-08 05:35:39

标签: javascript html button time hide

如何在点击时使HTML按钮消失,然后在2秒后重新出现?我找到了一些方法,但我需要它来处理我已经拥有的代码。我怎么能做到这一点?

<script language="JavaScript">

  function enableTorch(milliSeconds) {
    ipwajax('enabletorch');
    window.setTimeout("ipwajax('disabletorch');",milliSeconds);
  }

</script>
<input type="button" style="font: bold 20px Arial" onclick="enableTorch(1500);" value="LED ON">

4 个答案:

答案 0 :(得分:1)

<!--
$("p").hide()
Demonstrates the jQuery hide() method, hiding all <p> elements.
-->
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("button").click(function(){
    $("button").hide();
    $("button").show(2000);/*2 sec time*/
  });
});
</script>
</head>

<body>

<button>Click me</button>
</body>
</html>

这个将隐藏按钮并在2秒内重新显示

答案 1 :(得分:1)

检查

function enableTorch(milliSeconds) {
   ipwajax('enabletorch');
   document.getElementById('torch').style.display="none";
   setTimeout(function(){ipwajax('disabletorch');document.getElementById('torch').style.display='inline'}, milliSeconds);
  }


<input type="button" id = "torch" style="font: bold 20px Arial" onclick="enableTorch(1500);" value="LED ON">

答案 2 :(得分:1)

$(document).ready(function(){
  $("button").click(function(){
    $(this).hide().show(2000);
  });
});

答案 3 :(得分:0)

在这里你http://jsfiddle.net/4eCrQ/

$('.first').on('click', function() {
    $('.second').hide();
    setTimeout(function() {
        $('.second').show();
    }, 2000);
});