jquery - Jquery blur not working when scrolling the page
问题描述
I am using jquery blur for error validation.When I am typing on textbox and click outside It's working fine. But When I am scrolling page blur is not triggered.
Look at the jquery example itself https://api.jquery.com/focusout/
When you are on focus on input and scrolling the page it's not focused out or blurred. May I know how to fix this?
解决方案
blur()
没有触发?...自己触发...
在 scroll 上,使用以下方法触发 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;"> </div>
更多信息可以在这里建立:
trigger()
:https ://api.jquery.com/trigger/
scroll()
:https ://api.jquery.com/scroll/
推荐阅读
- sql-server - 使用 SQL 创建 SCD 类型 2
- java - 用于处理需要限时释放的队列上的消息的优先队列
- sql - 用一行而不是几行表示数据
- c++ - Outlook 加载项无法写入注册表位置 HKEY_LOCAL_MACHINE\\SOFTWARE
- wpf - 如何在 WPF DataGrid 中添加带有文本框的行以用作搜索框
- wso2 - 我可以在 wso2 api 管理器中添加租户明智的策略吗
- opengl - 带有 GL_DYNAMIC_DRAW 的 OpenGL VAO
- reactjs - Format.js 提取嵌套在组件中的 FormattedMessage
- vue.js - 在 vuejs 中上传时为空路径
- python - 如何连接图表的两个部分?在蟒蛇