问题
I am trying to get the value from the name in a hidden field. The name / value is created dynamically. The ID column is created sequentially. here is the HTML
<div="campAddons">
<input type="hidden" id="column2" name="Housing" value="108">
<div>
here is my jquery
column1Name = $("#campAddons input[id='column2']").val(name);
console.log(column1Name);
i keep getting object.object in the console log.
回答1:
Name is an attribute. So you have to use .attr()
to get its value. Please read here to learn more about it.
Try,
column1Name = $("#campAddons input[id='column2']").attr('name');
console.log(column1Name);
OR
column1Name = $("#column2").attr('name');
console.log(column1Name);
DEMO
来源:https://stackoverflow.com/questions/20526451/jquery-get-name-value-of-hidden-field