简体   繁体   English

在加载fieldset上,如何聚焦于所选的文本字段

[英]on loading fieldset how can i focus to my selected textfield

I have more than one fieldset in my page. 我的页面中有多个fieldset Each has few number of textfield in it. 每个中都有几个textfield

I want to focus any selected textfield . 我想聚焦任何选定的textfield How can i do this? 我怎样才能做到这一点?

suppose if i have like this 假设我有这样的话

<fieldset>
<legend>First Page</legend>
<input id="bp1" name="bp1" type="text" AUTOCOMPLETE=OFF />
<input id="bp2" name="bp2" type="text" AUTOCOMPLETE=OFF />
<input id="bp3" name="bp3" type="text" AUTOCOMPLETE=OFF />
</fieldset>

<fieldset>
<legend> Next Page</legend>
<input id="other1" name="other1" type="text" AUTOCOMPLETE=OFF />
<input id="other2" name="other2" type="text" AUTOCOMPLETE=OFF />
<input id="other3" name="other3" type="text" AUTOCOMPLETE=OFF />

</fieldset>
<div id="navigation" style="display:none;">
                    <ul>
                        <li class="selected">
                            <a href="#">First Page</a>
                        </li>
                        <li>
                            <a href="#">Next Page</a>
                        </li>

I want to focus on my 3rd textfield(id="bp3") in first page and in the next page i want to focus to 2nd textfield ie id="other3". 我想在第一页上关注我的第三个文本字段(id =“ bp3”),在下一页中,我要关注第二个文本字段,即id =“ other3”。 How to do this? 这个怎么做?

use focus() on the field you want to focus like 在要聚焦的字段上使用focus()

document.getElementById('bp3').focus()

then on next page visibility event ie onclick of next page 然后在下一页visibility事件,即下一页的onclick

<a href="#" onclick="document.getElementById('other3').focus()">Next Page</a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM