The requirements and code are as follows:
"This is my code:"
<input type="text" id="price2" value="333"/><input type="text" id="trueprice" value="" />
<script type="text/javascript">document.getElementById("price2").onkeyup = function() {document.getElementById("trueprice").value = this.value;}</script>Question: Now when you open this page, the value of trueprice is empty by default. How can you achieve the default opening of trueprice is the same as price2? (price2 is a dynamic value)
<input type="text" id="trueprice" value="" /> is fixed and cannot be modified
A simple implementation of mine:
<!DOCTYPE HTML><html><head><meta http-equiv="content-type" content="text/html;charset=utf-8"><title>Test</title></head><body><input type="text" id="price2" value="333" onkeyup="test(this.value);"/><input type="text" id="trueprice" value="" /><script type="text/javascript">var price2 = document.getElementById("price2").value;document.getElementById("trueprice").value = price2;function test (defaultVal) {document.getElementById("trueprice").value = defaultVal;}</script></body></html>Effect:
The content entered in the first text box can be synchronized to the second text box