问题
I need to store the values in the hidden text field when I select any check box from the page
<input type="checkbox" name="checked1" value="checked1" onselect="getvalue()">
<input type="checkbox" name="checked1" value="checked2" onselect="getvalue()">
<input type="checkbox" name="checked1" value="checked3" onselect="getvalue()">
When I any of the check box that will store into below hidden field:
<input type="hidden" />
回答1:
Using jquery, and assuming you gave an id (here "myhidden") to your hidden input, you can do this :
$('input[type="checkbox"]').change(function(){
$('#myhidden').val($(this).val());
});
This fiddle demonstrates it : http://jsfiddle.net/dystroy/e6jpG/
来源:https://stackoverflow.com/questions/10716945/assign-value-to-hidden-field-when-checkbox-checked-javascript