使用jQuery检测HTML5的自动聚焦功能

每当文本字段集中在我的网站上时,我都会使用jQuery执行操作.只要我通过点击它手动聚焦文本字段,一切正常.

但是:我正在使用HTML5自动聚焦功能,而jQuery没有检测到文本字段自动被聚焦.如何手动或自动聚焦文本字段,如何确保我的脚本执行操作?

现在,我正在使用……

$("input:text,input:password").focus(function() { });

…检测文本字段何时突出显示.

解决方法

如果您只需要担心初始页面加载时的自动对焦,那么可能是这样的?

在pageload上触发autofocus’d元素上的焦点事件:

<script>
$(document).ready( function () {
  $("input:text,input:password").focus(function () { });//attach the focus event

  $('input[autofocus]').trigger('focus');//force fire it on the autofocus element
});
</script>

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...