JavaScript 中 onfocus 事件的使用情況是什麼?


當元素獲得焦點時,會觸發 onfocus 事件。你可以嘗試執行以下程式碼以瞭解如何在 JavaScript 中實現onfocus 事件。

示例

<!DOCTYPE html>
<html>
   <body>
      <p>Write below:</p>
      <input type = "text" onfocus = "newFunc(this)">
      <script>
         function newFunc(x) {
            x.style.background = "blue";
         }
      </script>
   </body>
</html>

更新於: 2020 年 5 月 22 日

477 次瀏覽

開啟您的職業生涯

透過完成該課程獲取認證

開始
廣告
© . All rights reserved.