簡體   English   中英

無法從文本框獲取輸入

[英]Can't get input from textbox

我試圖從文本框中獲取輸入,但它不起作用。

我也無法讓我的變量在函數之間工作。

 var first_name = document.getElementById('first'); var last_name = document.getElementById('first'); function firstNameClick() { window.document.f.note.value = "Enter first name, then last name."; window.document.f.note.size = 25; } function firstNameLeave() { window.document.f.note.size = 10; window.document.f.note.value = ""; first_name = document.getElementById('first'); if ((first_name != "") && (last_name != "")) { window.document.f.firstDisplay.value = (first_name); window.document.f.firstDisplay.value = (last_name); } else { window.document.f.firstDisplay.value = ""; } } function lastName() { last_name = document.getElementById('last'); if ((first_name != "") && (last_name != "")) { window.document.f.lastDisplay.value = (last_name); window.document.f.firstDisplay.value = (first_name); } else { window.document.f.lastDisplay.value = ""; } }
 <form name="f"> <font>First Name</font> </br> <input type="text" id="first" name="first" size=35 onClick="firstNameClick();" onBlur="firstNameLeave();"> </br> </br> <font>Last Name</font> </br> <input type="text" id="last" name="last" size=35 onBlur="lastName();"> </br> </br> <font>Note</font> </br> <input type="text" name="note" size=10 value="" readonly> </br> </br> <font>Display</font> </br> <input type="text" name="firstDisplay" size=25 value="" readonly> </br> <input type="text" name="lastDisplay" size=25 value="" readonly> </form>

 <html> <head></head> <body> <form name="f"> <font>First Name</font> <br> <input type="text" id="first" name="first" size=35 onClick="firstNameClick();" onBlur="firstNameLeave();"> <br> <br> <font>Last Name</font> <br> <input type="text" id="last" name="last" size=35 onBlur="lastName();"> <br> <br> <font>Note</font> <br> <input type="text" name="note" size=10 value="" readonly> <br> <br> <font>Display</font> <br> <input type="text" name="firstDisplay" size=25 value="" readonly> <br> <input type="text" name="lastDisplay" size=25 value="" readonly> </form> <script> var first_name = document.getElementById('first').value; //add .value var last_name = document.getElementById('last').value; // add .value and use 'last' in attribute selector you had first window.document.f = document.querySelector('f'); function firstNameClick() { window.document.f.note.value = "Enter first name, then last name."; window.document.f.note.size = 25; } function firstNameLeave() { window.document.f.note.size = 10; window.document.f.note.value = ""; first_name = document.getElementById('first').value; // add.value if ((first_name != "") && (last_name != "")) { window.document.f.firstDisplay.value = (first_name); window.document.f.lastDisplay.value = (last_name); //use lastDisplay } else { window.document.f.firstDisplay.value = ""; } } function lastName() { last_name = document.getElementById('last').value; //add .value if ((first_name != "") && (last_name != "")) { window.document.f.lastDisplay.value = (last_name); window.document.f.firstDisplay.value = (first_name); } else { window.document.f.lastDisplay.value = ""; } } </script> </body> </html>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM