【问题标题】:Problems with focus() in an input radio in FirefoxFirefox 输入单选中的 focus() 问题
【发布时间】:2016-10-19 10:32:57
【问题描述】:

我在 Firefox 中发现了一个问题,当您尝试在输入收音机中聚焦时。它不会在输入中获得焦点,除非您之前使用 tab 来关注输入。之后它可以正常工作。有谁知道如何解决它?提前致谢!

<!DOCTYPE html>
<html>
<body>

Radio Button: <input type="radio" id="myRadio">

<p>Click the buttons below to give focus and/or remove focus from the radio button.</p>

<button type="button" onclick="getFocus()">Get focus</button>
<button type="button" onclick="loseFocus()">Lose focus</button>

<script>
function getFocus() {
    document.getElementById("myRadio").focus();
}

function loseFocus() {
    document.getElementById("myRadio").blur();
}
</script>

</body>
</html>

【问题讨论】:

  • 它在 Firefox(v47.0 和 v47.0.1)中为我工作。唯一的事情是没有突出显示...但是如果您单击“获取焦点”然后单击“条形空间”,您将看到收音机如何更改为选中状态。

标签: javascript html focus


【解决方案1】:

它在 Firefox(v47.0 和 v47.0.1)中为我工作。唯一的问题是没有突出显示它......但是如果你添加一些像下面这样的 CSS,你会看到它是如何正常工作的:

input#myRadio:focus { outline: 7px solid yellow; }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-21
    • 2016-07-14
    • 2012-05-16
    • 2015-06-08
    • 2011-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多