【问题标题】:onblur function doesn't work in google chrome and firefoxonblur 功能在 google chrome 和 firefox 中不起作用
【发布时间】:2021-10-16 17:41:00
【问题描述】:

我正在开发 mvc 应用程序。在开发过程中,我遇到了一个非常奇怪的问题,我有三个文本框,每个文本框都需要调用 onblur 事件。 当我执行代码时,仅为第一个文本框调用事件,而不是为第二个和第三个文本框再次调用事件。这是我的代码

<html>
  <head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script>
     $(document).ready(function(){  
        $("#a1,#a2,#a3").blur(function(){
        alert("This input field has lost its focus.");
        });  
     });
  </script>
  </head>
  <body>

    Enter your name: <input type="text" class="c1" id="a3">
    <br><input type="text" class="c1" id="a1">
    <br><input type="text" class="c1" id="a2">
    <p>Write something in the input field, and then click outside the field to lose focus (blur).</p>

 </body>
</html>

【问题讨论】:

  • 它似乎有效? jsfiddle.net/ope79u3k
  • 不要使用警报调试,使用console.log($(this).attr('id')) 你看它工作正常

标签: javascript jquery model-view-controller


【解决方案1】:

我认为您的浏览器/沙箱中可能会出现一些警报阻塞,但 onblur 工作正常(尝试仅在控制台记录您当前显示警报的内容)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多