element.select()在Firefox中不起作用

时间:2017-07-06 22:48:44

标签: javascript google-chrome firefox

我有一个测试,我去Google.com并在控制台中运行以下命令:

test = document.querySelector('#lst-ib') //#lst-ib is the ID of Google's search bar
test.value = 'abcd'
test.select()
window.getSelection().toString() //expected return value of 'abcd'

如果我在Chrome或Safari中运行此测试,我会得到预期的返回值' abcd' - 表示已选择输入中的文本。

在FireFox中,我得到一个空字符串。

有没有人有解释?当我从脚本而不是控制台在我自己的页面上运行此代码时,我会得到相同的行为。

我正在使用Firefox 54.01和Chrome 59.0.3071.115

进行测试

1 个答案:

答案 0 :(得分:3)

这是Firefox的已知错误。 16年又算了。

https://bugzilla.mozilla.org/show_bug.cgi?id=85686