當用戶在 HTML 中開啟或關閉
元素時執行指令碼?


當用戶開啟或關閉 <details> 元素時,會觸發 ontoggle 事件。你可以嘗試執行以下程式碼來實現 ontoggle 事件屬性 -

示例

<!DOCTYPE html>
<html>
   <body>
      <h2>Details</h2>
      <p>You need to join office from Feb23<p>
      <details ontoggle="display()">
         <summary>More Information</summary>
         <p>Timings: 9 to 5:30</p>
         <p>Office location: Hyderabad</p>
      </details>
     
      <script>
         function myFunction() {
            alert("Timings, office location, etc");
         }
      </script>
   </body>
</html>

更新日期: 2020 年 3 月 3 日

109 次瀏覽

啟動您的 職業生涯

完成該課程即可獲得認證

開始
廣告
© . All rights reserved.