簡體   English   中英

當用戶使用javascript函數單擊時顯示div

[英]Display a div when a user clicks using a javascript function

用戶單擊按鈕時,我需要在網頁上顯示div。 有人知道怎么做嗎?

到目前為止我的代碼:

<body onload ="init()">
      <input type="button" value="Display the div tree" onclick="check();" />

      <script ="text/javascript">

      function check() {
      // I'd like to display on the page the div tree
      }

     </script>

      <div id = "tree" style="display:none"> // I don't want to display it unless the user clicks on the button "Display the div tree"
      </div>      

</body>

謝謝,

布魯諾

document.getElementById('tree').style.display='';

包括在您的檢查功能中

我不確定我是否理解這個問題,這似乎有點容易:

function check() {
  document.getElementById('tree').style.display=''; // or display='block';
}

編輯:
此操作對您不起作用的原因是代碼中的錯誤。 請更改此行:

<script ="text/javascript">

<script type="text/javascript">

一切都會好起來的。 同樣,您應該將腳本放置在文檔的head ,但這並不是絕對必要的。

暫無
暫無

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

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