當 HTML 中的元素失去焦點時執行指令碼?


使用 onblur 屬性在元素失去焦點時執行指令碼。

示例

<!DOCTYPE html>
<html>
   <body>
      <p>Type text below!</p>

      Country: <input type = "text" name = "myid" id = "myid" onblur = "display()">

      <script>
         function display() {
            var str = document.getElementById("myid");
            str.value = str.value.toUpperCase();
         }
      </script>

   </body>
</html>

更新於: 03-3-2020

242 次瀏覽

開啟你的 職業道路

完成課程即可獲得認證

開始學習
廣告
© . All rights reserved.