gpt4 book ai didi

javascript - 单击时单选按钮组内的文本输入在 Firefox 中失去焦点

转载 作者:技术小花猫 更新时间:2023-10-29 12:52:05 25 4
gpt4 key购买 nike

我在 Firefox 中遇到问题,如果您单击 <input type="text">在 Firefox 中,焦点立即转移到单选按钮兄弟。

该行为在 Chrome 中正常运行。我需要额外的 Javascript 来解决这个问题吗?

Here's the JsFiddle

最佳答案

似乎 Firefox 实际上根据 W3C 做了正确的事情:

If the for attribute is not specified, but the label element has a labelable element descendant, then the first such descendant in tree order is the label element's labeled control.

您的标签包裹着两个输入元素,因此当您在文本框中单击时,单选按钮(树顺序中的第一个此类后代)获得焦点。

结果将根据浏览器如何实现此规则而有所不同,因此要确保跨浏览器的结果是肯定的,您需要 JavaScript 介入。

关于javascript - 单击时单选按钮组内的文本输入在 Firefox 中失去焦点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15253646/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com