滚动页面时 Jquery 模糊不起作用



我正在使用jquery blur进行错误验证。当我在文本框上键入并单击外部时,它工作正常。但是当我滚动页面模糊时不会触发。

看看jquery示例本身 https://api.jquery.com/focusout/

当您专注于输入并滚动页面时,它不会聚焦或模糊。 我可以知道如何解决这个问题吗?

blur()没有触发?自己触发它...

在滚动时,使用trigger()方法触发模糊事件:

$(document).ready(function() {
$("#test").on("blur", function() {
if (isNaN($("#test").val())) {
$("#test").css("border-color", "red");
$("#result").html("Expecting numbers");
}
else {
$("#test").css("border-color", "blue");
$("#result").html("Good input");
}
});
$(this).on("scroll", function() {
$("#test").blur();
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="test"/>
<p id="result"></p>
<!-- This section has nothing to do ... it just add some content to make the page scrollable -->
<div style="height:99999px; width:200px;">&nbsp;</div>

更多信息可以在这里找到:

trigger(): https://api.jquery.com/trigger/

scroll(): https://api.jquery.com/scroll/

最新更新