2014-10-29 40 views
0

關於這個問題,在stackoverflow中有很多類似的話題,但它不適合我。如何在Firefox或Chrome中模擬按鍵到文本框?

我與谷歌雲端硬盤API教程的嘗試:

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

現在,我想在文本框「編輯1」和文本框「編輯2」將更新到autotyping。

我試着用:

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

然後將文本更改,但事件不被谷歌雲端硬盤API的認可,「編輯2」的文本不會更改。

任何建議是值得歡迎的。

非常感謝您

+0

不,我的問題沒有重複 – 2014-10-29 14:48:27

回答

0

嘗試jQuery的事件即:

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

不是什麼被問到。 OP要求模擬按鍵,而不是聽它。 – Kroltan 2014-10-29 13:43:28

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

+0

這裏沒有必要使用jquery。 – 2014-10-29 13:43:27

+0

謝謝你所有的答案,但我擔心我描述錯了。我希望Google Drive API識別文本框的值更改,Google Drive會更新其他文本框的值(而不是使用HTML或Javascript代碼)。 TKS這麼多 – 2014-10-29 14:47:35

+0

下面是我的代碼: – 2014-10-29 14:55:05