簡體   English   中英

單擊按鈕5次后如何顯示圖像

[英]how do display an image after button is clicked 5 times

是否有一個JavaScript可以讓我顯示一個按鈕,用戶單擊該按鈕即可加載5張圖片中的任何一張。 然后,單擊按鈕后,“ X”按鈕下方的Hello World出現次數

我已經能夠找到能夠計算單擊按鈕次數的腳本,但是單擊一定次數后,什么都不會導致動作。

任何建議表示贊賞。

您可以如下設置代碼:

<style type="text/css">
  #hello {
    display: none;
  }
</style>
<script type="text/javascript">
  var numClicks = 0;
  var x = 5;
  function action() {
    numClicks++;
    if (numClicks == x) {
      //do something here
      //get hello div and make it visible
      var hello = document.getElementById("hello");
      hello.style.display = 'block';
    }
  }
</script>    
<button type="button" onclick="action()">a button</button>
<div id="hello">Hello World!</div>

暫無
暫無

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

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