get value of hidden field

2019-02-16 10:28发布

问题:

I reference the hidden field like:

var h = document.getElementById('myHiddenField');

How can I set the value to 100, and then output the value using a simple alert();?

回答1:

var h = document.getElementById('myHiddenField');
h.value = 100;
alert(h.value);


回答2:

//get value
var hidderValue = document.getElementById('myHiddenField').value;

//set value
document.getElementById('myHiddenField').value = 200;


回答3:

The value property of the element.



回答4:

Maybe you want to set hidden field's value IN the html part. To do so write:

<input type="hidden" id="myHiddenField" value="100"></input>