JavaScript 中 onfocusout 事件的用法是什么?

htmljavascriptprogramming scripts更新于 2026/1/14 3:56:17

当元素失去焦点时,会触发 onfocusin 事件。您可以尝试运行以下代码来了解如何在 JavaScript 中实现 onfocusout 事件。

示例

<!DOCTYPE html>
<html>
   <body>
      <p>下面写:</p>
      <p>失去焦点后,输入检查的背景颜色会发生变化。</p>
      <input type = "text" onfocusout = "newFunc(this)">
      <script>
         function newFunc(x) {
            x.style.background = "blue";
         }
      </script>
   </body>
</html>

相关文章


有用资源