Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/417.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 在<;em>;容器中的元素_Javascript_Jquery_Html - Fatal编程技术网

Javascript 在<;em>;容器中的元素

Javascript 在<;em>;容器中的元素,javascript,jquery,html,Javascript,Jquery,Html,给定页面中的容器div,如何将焦点赋予特定元素 我尝试了以下方法: <div id="modalTextDocument" style="height:15px;overflow:scroll;"> <em>Hello</em> ... various text... <em>other highlighted element<em> you can see this only scrolling... etc... </div&

给定页面中的容器div,如何将焦点赋予特定元素

我尝试了以下方法:

<div id="modalTextDocument" style="height:15px;overflow:scroll;">
<em>Hello</em>
... various text...
<em>other highlighted element<em> you can see this only scrolling...
etc...
</div>

快速解决方案是为每个元素添加
tabindex
,您希望通过
focus
聚焦这些元素,默认情况下,这些元素不可聚焦

通过指定tabindex,基本上可以告诉浏览器元素获得焦点的顺序,而且可以为任何元素设置tabindex,而不仅仅是那些默认情况下能够获得焦点的元素

$('div#modalTextDocument')。查找('em')[1]。焦点()

你好
... 各种文本。。。
其他突出显示的元素您只能看到此滚动。。。
等

em
元素无法按默认值接收焦点-您必须首先通过
tabindex
属性“启用”。
$('div#modalTextDocument').find('em')[1].focus();