关注基于锚链接的textarea [英] Focus on textarea based from anchor link

查看:135
本文介绍了关注基于锚链接的textarea的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的网站有一个消息功能,当用户点击一个回复按钮时,他们会被重定向到消息,并通过锚链接获得textarea焦点。



<所以链接结构是这样的:

$ p $ view_message / 4fad37da1df#reply

谢谢 $(window.location.hash).attr(tabindex,-1())

$ $ p $ )。焦点();
}

它应该检查网址是否有散列,如果,给目标的tabindex属性值为-1,并应用焦点。



请参阅 https://stackoverflow.com/a/6188217/430191 为tabindex属性的原因(有关IE / Chrome / Safari中的键盘焦点的相关问题)


I have a messaging function in my site that when a user clicks on a reply button they get redirected to the message and have the textarea focus based from the anchor link.

so the link structure is like this:

view_message/4fad37da1df#reply

thanks

解决方案

Try:

if (window.location.hash) {
  $(window.location.hash).attr("tabindex", -1).focus();
}

It should check if the url has a hash in it, and if it does, give the target the tabindex attribute with a value of -1 and apply focus.

See https://stackoverflow.com/a/6188217/430191 for the reason for the tabindex attribute (a related issue about keyboard focus in IE/Chrome/Safari)

这篇关于关注基于锚链接的textarea的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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