简体   繁体   English

更新并在输入标签中保留值

[英]Updating and keeping a value in an input tag

I'm trying to write a simple javascript program, which updates the value of an input type="hidden" . 我正在尝试编写一个简单的javascript程序,该程序将更新input type =“ hidden”的值

In my script, a particular value gets changed too often, so I'm trying to use the below method to store the previous value. 在我的脚本中,特定值经常更改,因此我尝试使用以下方法存储先前的值。

<input type="hidden" value="" id="test">

<script>
alert(document.getElementById('test').value);
document.getElementById('test').innerHTML=10;
alert(document.getElementById('test'));
</script>

10 doesn't gets stored. 10不存储。 How can I make it work ? 我该如何运作? My prime motive is, to have the previous value ( And the last n values changed ), and updated value at the same time. 我的主要动机是要具有先前的值( 最后n个值已更改 ),并且要同时更新值。 If there are any other methods to obtain this required task, I'd be happy to listen. 如果还有其他方法可以完成此任务,我很乐意听。

Try this example: 试试这个例子:

alert(document.getElementById('test').value);
document.getElementById('test').value = "10";
alert(document.getElementById('test').value);

http://jsfiddle.net/HTq8J/ http://jsfiddle.net/HTq8J/

Try this: 尝试这个:

<input type="hidden" value="" id="test">

<script>
  alert(document.getElementById('test').value);
  document.getElementById('test').value = '10';
  alert(document.getElementById('test').value);
</script>

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

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