Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 加载字段集时,如何将焦点集中到选定的文本字段_Javascript_Jquery_Focus_Textfield_Fieldset - Fatal编程技术网

Javascript 加载字段集时,如何将焦点集中到选定的文本字段

Javascript 加载字段集时,如何将焦点集中到选定的文本字段,javascript,jquery,focus,textfield,fieldset,Javascript,Jquery,Focus,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 /&

我的页面中有多个
字段集
。每个字段中都有少量的
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”。如何做到这一点?

在你想聚焦的领域使用

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

然后在下一页<代码>可见性事件,即单击下一页


您在任何给定时间只能聚焦文档中的一个元素?是的,我只想聚焦所选文本字段中的一个,而不是第一个文本字段。我想知道在什么情况下我应该调用此脚本?我想在加载FieldSetInAsenacy时执行脚本-您可以将此脚本称为身体或文档的onload事件。readyState检查如果我将其放置在身体上,则焦点将只工作一次。我希望加载每个字段集,以便我选择的文本字段在将代码放置在加载字段集的位置时聚焦。或者共享代码如何加载字段集以帮助您。我的代码非常长,因此我用类似的代码以更短的方式编辑了我的问题