不兼容的 html 页面中的 TabIndex 控件
我有一个 html 页面,我无法在其中放置 DOCTYPE (我不允许这样做)。另外,我需要让它在 IE 8 上运行! 然后是一个复选框+标签的东西。 例如,这个:
<input id="daffodils" type="checkbox" title="daffodil factsheet" name="daffodils" value="checkbox" tabindex=2>
<label for="daffodils">Daffodils</label>
<input id="tulips" type="checkbox" title="tulip factsheet" name="tulips" value="checkbox" tabindex=3>
<label for="tulips">Tulips</label>
我的问题: 我想在按 Tab 键时突出显示复选框,但使用此代码时,只有标签会突出显示。我尝试使用 TabIndex。但这没有帮助。 当然,可以选中/取消选中该复选框,但我希望突出显示该复选框。 (突出显示 - 我的意思是..物体周围的虚线方块)
谢谢。
I have an html page where I cannot put a DOCTYPE (I am not allowed to). Plus, I need to make it work on IE 8!
Then there is a checkbox + label thing.
For example, this:
<input id="daffodils" type="checkbox" title="daffodil factsheet" name="daffodils" value="checkbox" tabindex=2>
<label for="daffodils">Daffodils</label>
<input id="tulips" type="checkbox" title="tulip factsheet" name="tulips" value="checkbox" tabindex=3>
<label for="tulips">Tulips</label>
My problem:
I want to get the checkbox highlighted when I Tab around, but with this code, only the Labels get highlighted. I tried using TabIndex. but it didn't help.
Of course, the checkbox can be checked/unchecked, but I wanted the checkbox to be highlighted. (By highlighted - I mean ..the dotted square around an object)
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这不太漂亮,但可能对您有用:
请注意输入框中的
onfocus
和onblur
事件。编辑:
如果您愿意使用 jQuery 库,则可以通过以下方式轻松摆脱输入标记内的
onfocus
和onblur
事件:只需添加和删除focus
类:我确信有人可以编写 JS 代码来执行相同的操作,但我更喜欢 jQuery。
This is not pretty, but it might work for you:
Notice the
onfocus
andonblur
events on the input boxes.Edit:
If you're open to using the jQuery library, you can easily get away from the
onfocus
andonblur
events inside the input tags by just adding and removing thefocus
class:I'm sure someone could write the JS code to do the same, but I prefer jQuery.
可以不使用
吗?
那就好了。
对于每个复选框,将它们包围在
一切就这样完成了。
Is it allowed not to use
<label>
?That will be fine.
for every checkbox, suurround them in
<div style="cursor:default;" onclick="this.childNodes[0].focus();this.childNodes[0].click();"><input /><span /></div>
And that's all done.