Persyaratan dan kode adalah sebagai berikut:
"Ini kode saya:"
<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>Pertanyaan: Sekarang ketika Anda membuka halaman ini, nilai Trueprice kosong secara default. Bagaimana Anda bisa mencapai pembukaan default Trueprice sama dengan harga2? (harga2 adalah nilai dinamis)
<input type = "text" id = "trueprice" value = "" /> ditetapkan dan tidak dapat dimodifikasi
Implementasi sederhana saya:
<! Doctype html> <html> <head> <meta http-equiv = "tipe konten" konten = "teks/html; charset = utf-8"> <title> tes </ title> </head> <body> <input type = "text" id = "price2" value = "333" onkeyup = "tes =" tes ("ini" nilai "333" di atas " id = "trueprice" value = "" /> <script type = "text /javaScript"> var price2 = document.geteLementById ("price2"). value; document.geteLementById ("trueprice"). value = function test (defaultVal) {document.getElementById ("trueprice" nete). DefaultVal;} </script> </body> </html>Memengaruhi:
Konten yang dimasukkan dalam kotak teks pertama dapat disinkronkan ke kotak teks kedua