如果没有div的tabindex属性,Jquery .focus()无法正常工作 [英] Jquery .focus() not working without tabindex attribute of div

查看:227
本文介绍了如果没有div的tabindex属性,Jquery .focus()无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在不设置div的tabindex的情况下使jquery .focus()工作

How can I make jquery .focus() to work without setting tabindex of a div

  $("#msgdiv").focus();

<div id="msgdiv" tabindex="100"> </div>

此最佳做法是什么

我想要实现的目标:更改密码后,我想显示密码已更改的确认消息,并将焦点放在该div上。

what i want to achieve: After changing the password i want to display the acknowledgment message that the password has been changed and put focus on that div.

推荐答案

简单地说,如果没有tabindex,你就无法专注于div,请参阅文档

Simply, you can't do focus on a div without tabindex, see documentation.

不知道你想用这个代码片段实现什么,但是如果你想要触发焦点事件,你应该使用触发器

Don't really know what you wanna achieve with this code-snippet, but if you wanna trigger a focus event, you should use trigger:

$("#msgdiv").trigger('focus');

这篇关于如果没有div的tabindex属性,Jquery .focus()无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆