将变量粘贴到document.activeElement.value中

时间:2014-07-22 20:51:17

标签: javascript jquery google-chrome-extension

我有一个Chrome扩展程序,需要将变量的内容粘贴到文本区域/框中。

//copy_paste1 is a variable which has a string stored in it at this point. 
// Exact value is Hi'
if (evt.keyCode == 51 && evt.ctrlKey) {
    curElement=document.activeElement;
    alert(copy_paste1);
    curElement.value=copy_paste1;
    alert("Done");
}

这是执行的代码。当我尝试按下 Ctrl + 3 (keyCode Ctrl + 51)对随机元素如文字说。我收到警告Hi。然后提醒Done

但是当我在文本区域中这样做时。我收到一个空白警报,没有任何内容被复制到文本区域,然后是一个警告Done

当我将curElement.value=copy_paste1更改为curElement.value="Hi"时,文本区域会发生变化。当活动元素是文本区域或输入框时,为什么我无法检索变量?

0 个答案:

没有答案
相关问题