Jquery get Name value of hidden field

余生长醉 提交于 2019-12-31 07:04:03

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!