Set the Value of a Hidden field using JQuery

吃可爱长大的小学妹 提交于 2019-11-30 00:36:30

问题


I want to set the value of a hidden field, using JQuery.

Hidden Field:

<input id="chag_sort" type="hidden" name="chag_sort">

My JQuery:

 $("#input[name=chag_sort]").val(sort2);

What am I doing wrong? I should also mention in console that sort2 does in fact have a value: DESC.


回答1:


The selector should not be #input. That means a field with id="input" which is not your case. You want:

$('#chag_sort').val(sort2);

Or if your hidden input didn't have an unique id but only a name="chag_sort":

$('input[name="chag_sort"]').val(sort2);



回答2:


Drop the hash - that's for identifying the id attribute.




回答3:


If you have a hidden field like this

  <asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Eval("VertragNr") %>'/>

Now you can use your value like this

$(this).parent().find('input[type=hidden]').val()



来源:https://stackoverflow.com/questions/5998385/set-the-value-of-a-hidden-field-using-jquery

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