自动对焦在Firefox上不起作用,从另一个页面来时不起作用 [英] Autofocus doesn't work on Firefox and doesn't work when coming from another page
问题描述
我正在使用Javascript创建我的页面。这是一个登录页面,我需要使用用户名输入文本的自动对焦。此操作适用于IE和Chrome,但不适用于Mozilla!
这是我使用JS添加的HTML:
'< input id =usernameclass = loginInputdata-bind =value:userName,valueUpdate:\'afterkeydown\'type =textname =Userautofocus><! - User Input text end / - >'
当我使用Mozilla加载页面时,这个输入是这样设置的:
< input id =usernameclass =loginInputtype =textautofocus =name =Userdata-bind =value: userName,valueUpdate:'afterkeydown'>
我真的不明白为什么要设置autofocus属性。我甚至尝试通过使用JQuery $(#username)。attr('autofocus','autofocus')
添加属性,并且仅适用于Chrome和IE。 p>
第二个问题出现在我从另一个页面进入登录页面时,每个浏览器都带有自动对焦问题。
你可以帮我吗?
$ p> $( #用户名)聚焦();
加载页面后。
I'm creating my page using Javascript. It is a login page and I need to use autofocus on username input text. This operation works on IE and Chrome, but doesn't on Mozilla! This is the HTML I have been adding using JS:
'<input id="username" class="loginInput" data-bind="value: userName, valueUpdate: \'afterkeydown\'" type="text" name="User" autofocus><!--User Input text end /-->'
When i load the page with Mozilla this input is set this way:
<input id="username" class="loginInput" type="text" autofocus="" name="User" data-bind="value: userName, valueUpdate: 'afterkeydown'">
I really can't understand why "autofocus" attribute is set in that way. I even tried by adding the attribute using JQuery $("#username").attr('autofocus','autofocus')
and works only on Chrome and IE.
The secondo problem comes when i go to the login page from another page and autofocus issue comes with every browser.
Can you help me?
You can try with:
$("#username").focus();
after the page has been loaded.
这篇关于自动对焦在Firefox上不起作用,从另一个页面来时不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!