我有一个文本框和一个选项菜单如下:
<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>
我想存储在文本框中输入的第一个值。当我调用onchange并且结果显示在同一输入文本框上时,值会更改。无论如何都存储第一个值
答案 0 :(得分:1)
您好以下代码将帮助您
<!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>
&#13;