繁体   English   中英

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

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

我的页面中有多个fieldset 每个中都有几个textfield

我想聚焦任何选定的textfield 我怎样才能做到这一点?

假设我有这样的话

<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>

我想在第一页上关注我的第三个文本字段(id =“ bp3”),在下一页中,我要关注第二个文本字段,即id =“ other3”。 这个怎么做?

在要聚焦的字段上使用focus()

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

然后在下一页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