I have a div element with several children. I need to disable tabbing in all of them. I have been using tabindex but is there any way to disable them all by setting a value in the parent.
我有一个带有几个孩子的div元素。我需要在所有这些中禁用Tab键。我一直在使用tabindex但有没有办法通过在父设置中设置一个值来禁用它们。
I don't want to touch the child divs.
我不想触摸孩子的div。
1 个解决方案
#1
0
I have no idea what your code looks like but you could grab the parent element and add the tabindex attribute to its children that are input
s using attr()
as follows:
我不知道你的代码是什么样的,但是你可以抓住父元素并将tabindex属性添加到使用attr()输入的子节点,如下所示:
$(".wrapper").children("input").attr("tabindex", "-1");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="wrapper">
<input type="text" name="1">
<input type="text" name="2">
<input type="text" name="3">
<input type="text" name="4">
</div>
NOTE: when you say "I don't want to touch the child divs" I'm assuming you mean you don't want to manually go through every instance and add tabindex as it would be time consuming?
注意:当你说“我不想触摸孩子div”时,我假设你的意思是你不想手动浏览每个实例并添加tabindex,因为它会耗费时间吗?
More info: http://api.jquery.com/attr/
更多信息:http://api.jquery.com/attr/
#1
0
I have no idea what your code looks like but you could grab the parent element and add the tabindex attribute to its children that are input
s using attr()
as follows:
我不知道你的代码是什么样的,但是你可以抓住父元素并将tabindex属性添加到使用attr()输入的子节点,如下所示:
$(".wrapper").children("input").attr("tabindex", "-1");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="wrapper">
<input type="text" name="1">
<input type="text" name="2">
<input type="text" name="3">
<input type="text" name="4">
</div>
NOTE: when you say "I don't want to touch the child divs" I'm assuming you mean you don't want to manually go through every instance and add tabindex as it would be time consuming?
注意:当你说“我不想触摸孩子div”时,我假设你的意思是你不想手动浏览每个实例并添加tabindex,因为它会耗费时间吗?
More info: http://api.jquery.com/attr/
更多信息:http://api.jquery.com/attr/