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


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

示例

<!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-05-22

477 次瀏覽

開啟您的 職業生涯

透過完成課程獲取認證

開始
廣告
© . All rights reserved.