如何在Firefox或Chrome中模拟按键到文本框?

时间:2014-10-29 13:18:56

标签: javascript html google-drive-api

有关此问题的stackoverflow中有许多类似的主题,但它对我不起作用。

我尝试使用Google Drive API教程:

https://developers.google.com/drive/realtime/realtime-quickstart#optional_view_a_quickstart_video

现在,我想在文本框中进行自动分型"编辑器1"和文本框"编辑器2"将更新。

我尝试过:

document.getElementById("editor1").value = "ABC";

然后文字发生了变化,但Google Drive API无法识别该事件,并且"编辑器2"不会改变。

欢迎提出任何建议。

非常感谢

3 个答案:

答案 0 :(得分:3)

答案是: Trigger a keypress/keydown/keyup event in JS/jQuery?

我没有声誉将此广告作为评论

答案 1 :(得分:0)

尝试jquery事件,即:

$("#editor1").keypress(function(){
    $("#editor2").val($(this).val());    // now you get the value of editor 1 in editor2
});

答案 2 :(得分:0)

尝试使用:

<强> HTML:

Input 1: <input type="text" id="input1" onkeydown="myFunction()"/>
Input 2: <input type="text" id="input2"/>

<强> JS:

function myFunction()
{
var x = document.getElementById("input1");
var y = document.getElementById("input2");
y.value=x.value;
}    

here's the Demo