简体   繁体   中英

How to Read the value in a hiddenField from javascript

我想在javascript / Jquery的隐藏字段中读取一个值。如何实现?

try this

var value=$('#HidennfieldID').val()

value will hold the value of hidden field

It's the same as for a regular field:

document.forms[xxx].elements[yyyy].value

xxx is the name of the form, or its number. yyyy is the name of the element (or its number).

You can also use document.getElementById() to get either the form or the field.

Use the field name or id, eg

var fVal = $('[name="name"]').val();
var fVal = $('#id').val();
<input type="hidden" value="12345" id="ixd" name='ixd' />

var val = document.getElementById("ixd").value;

This an example to read and write value just with pure javascript.

<input type="hidden" id="field-id" />

<script type="text/javascript">
    document.getElementById('field-id').value = "your value which you want to insert";
    alert(document.getElementById('field-id').value);
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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