html - 如何在html中设置自定义tabindex
问题描述
我有一个动态 html 页面,我div.id=myComponent
在这个 html 中有一个元素 ( ),input
里面有三个元素。
的元素是direction
和元素是这样的:body
rtl
div.id="myComponent"
ltr
<html>
<body style="direction: rtl;">
<input type="text" /> <!-- I can not set tabindex for this elements. beacuse these are generate the dynamically. -->
...
<!-- any elements -->
<div style="direction: ltr;" id="myComponent">
<span> <input tabindex="3" type="text" placeholder="y" /></span>
<span><input tabindex="2" type="text" placeholder="m" /></span>
<span><input tabindex="1" type="text" placeholder="d" /></span>
</div>
<input type="text" />
...
</body>
</html>
我需要它,当focus
输入时div.id="myComponent"
,如下所示:
d => m => y
但是是相反的。
我使用该tabindex
属性,但它无法正常工作。
你如何解决这个问题?
谢谢。
解决方案
您只需简单地更改您的 tabindex
<html>
<body style="direction: rtl;">
<input type="text" /> <!-- I can not set tabindex for this elements. beacuse these are generate the dynamically. -->
...
<!-- any elements -->
<div style="direction: ltr;" id="myComponent">
<span> <input tabindex="1" type="text" placeholder="y" /></span>
<span><input tabindex="2" type="text" placeholder="m" /></span>
<span><input tabindex="3" type="text" placeholder="d" /></span>
</div>
<input type="text" />
...
</body>
</html>
请尝试通过 JS 脚本首先关注您的 div
document.getElementById("myComponent").focus();
tabindex 应该像你期望的那样工作
推荐阅读
- python - Python:识别按下了哪些键,处理所有按下的键,然后打印结果
- ocaml - OCaml 中的语法:修改后传递数组
- python - Python Pytest 解压夹具
- python-3.x - Tensorflow 和 Keras 中的相同(?)神经网络架构在相同数据上产生不同的准确性
- jquery - Html 不呈现 Jquery 中的附加元素
- bigcommerce - 如何在 Bigcommerce 中获取路径图像?
- shell - Shell 脚本 - 将 .csv 文件中的分隔符从逗号更改为管道
- aem - 如何允许将某些组件添加到 AEM Experience Fragment(使用设计)?
- java - 主类不会自动创建客户端
- c - 如何获取字符串的特定部分?