-2
我有3個輸入元素。我想使用onkeyup事件從第一個輸入獲取值並將其複製到第三個輸入。但是當我輸入第一個輸入時,我仍然在第三個輸入中獲得一個空值。當用戶首先在輸入中輸入時,函數changethree()不會自動從輸入中獲取值。請幫我Javascript實現來自另一個onkeypress事件的onkeypress
<html>
<input type="text" id="satu" onkeyup="changetwo(this)" placeholder="input 1">
<br><br>
<input type="text" id="dua" onkeyup="changethree(this)" placeholder="input 2"><br><br>
<input type="text" id="tiga" placeholder="input 3">
<script>
\t function changetwo(a){
\t \t var target = document.getElementById('dua');
\t \t
\t \t target.value = a.value;
\t }
\t function changethree(a){
\t \t var target = document.getElementById('tiga');
\t \t
\t \t target.value = a.value;
\t }
</script>
</html>
感謝,它的工作原理。但如果我不能先改變輸入,如何解決這個問題,你有另一種解決方案嗎? –
我不確定你在問什麼。你是說你不能改變HTML,或者你不能輸入輸入字段? – Quinto
更改html –