Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/456.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript element.select()在Firefox中不起作用_Javascript_Google Chrome_Firefox - Fatal编程技术网

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

Javascript element.select()在Firefox中不起作用,javascript,google-chrome,firefox,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中运行此测试,我会得

我有一个测试,在那里我转到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这是Firefox的一个已知错误。16年,还在继续


这是Firefox的一个已知错误。16年,还在继续


为什么不直接使用test.value呢?您认为会有什么不同吗?这是为了更大的流来滚动我自己的“复制到剪贴板”功能。当然,但为什么要使用select和getSelection而不仅仅是value,因为execCommandcopy只处理页面上突出显示的文本。您不能直接向它传递值。为什么不直接使用test.value呢?您认为会有什么不同吗?这是为了更大的流来滚动我自己的“复制到剪贴板”功能。当然,但为什么要使用select和getSelection而不仅仅是value,因为execCommandcopy只处理页面上突出显示的文本。不能直接向其传递值。