ข้อกำหนดและรหัสมีดังนี้:
"นี่คือรหัสของฉัน:"
<input type = "text" id = "price2" value = "333" /> <อินพุต type = "text" id = "trueprice" value = "" />
<script type = "text/javascript"> document.getElementById ("price2"). onkeyup = function () {document.getElementById ("trueprice"). value = this.value;} </script>คำถาม: ตอนนี้เมื่อคุณเปิดหน้านี้ค่าของ TruePrice จะว่างเปล่าโดยค่าเริ่มต้น คุณจะบรรลุการเปิดตัวเริ่มต้นของ TruePrice ได้อย่างไรเช่นเดียวกับ Price2 ได้อย่างไร (ราคา 2 เป็นค่าไดนามิก)
<อินพุต type = "text" id = "trueprice" value = "" /> ได้รับการแก้ไขและไม่สามารถแก้ไขได้
การใช้งานง่าย ๆ ของฉัน:
<! doctype html> <html> <head> <meta http-equiv = "content-type" content = "text/html; charset = utf-8"> <title> ทดสอบ </title> </head> <body> id = "trueprice" value = ""/> <script type = "text/javascript"> var price2 = document.getElementById ("price2"). value; document.getElementById ("trueprice") ค่า = price2; ฟังก์ชั่นการทดสอบ (defaultVal)ผล:
เนื้อหาที่ป้อนในกล่องข้อความแรกสามารถซิงโครไนซ์กับกล่องข้อความที่สอง