Focus on textarea based from anchor link

限于喜欢 提交于 2019-12-10 12:29:48

问题


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


回答1:


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)



来源:https://stackoverflow.com/questions/10593111/focus-on-textarea-based-from-anchor-link

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!