jQuery获取隐藏字段的名称值
问题描述:
我正在尝试从隐藏字段中的名称中获取值.名称/值是动态创建的. ID列是按顺序创建的. 这是HTML
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>
这是我的jQuery
here is my jquery
column1Name = $("#campAddons input[id='column2']").val(name);
console.log(column1Name);
我一直在控制台日志中获取object.object.
i keep getting object.object in the console log.
答
名称是一个属性.因此,您必须使用.attr()
来获取其值.请阅读此处以了解有关此内容的更多信息.
Name is an attribute. So you have to use .attr()
to get its value. Please read here to learn more about it.
尝试
column1Name = $("#campAddons input[id='column2']").attr('name');
console.log(column1Name);
OR
column1Name = $("#column2").attr('name');
console.log(column1Name);