简体   繁体   English

使用javascript获取文本框中的第一个输入值

[英]Get first entered value in textbox using javascript

I have one textbox and one optionsmenu as follows: 我有一个文本框和一个选项菜单,如下所示:

<form>
<input type="text" id="input" size="20" onchange="func()">
<select id="no" >
<option>Options</option>
<option>Acre</option>   
<option>Ares</option>
<option>Cent</option>   
<option>m^2</option>
<option>ft^2</option>   
</select>
</form>

I want to store the very first value entered in the textbox. 我想存储在文本框中输入的第一个值。 As I call onchange and result is displayed on the same input textbox,the values changes. 当我调用onchange并将结果显示在同一输入文本框中时,值会更改。 Is there anyway to store the first value 反正有没有存储第一个值

Hi the following code will help you 嗨,以下代码将为您提供帮助

 <!DOCTYPE html> <html> <head> <title></title> <script type="text/javascript"> var firstValue = ""; function func() { if (firstValue == "") { firstValue = document.getElementById("input").value; } var currentValue = document.getElementById("input").value; alert("First Value is " + firstValue + " and Current Value is " + currentValue); } </script> </head> <body> <form> <input type="text" id="input" size="20" onchange="func()"> <select id="no"> <option>Options</option> <option>Acre</option> <option>Ares</option> <option>Cent</option> <option>m^2</option> <option>ft^2</option> </select> </form> </body> </html> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM