【发布时间】: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