jQuery 如何用Jquery填充asp.net隐藏字段
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2137778/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to fill asp.net hidden field with Jquery
提问by Martin Ongtangco
im trying this format:
我正在尝试这种格式:
$("#<%= hfWidth.UniqueID %>").val($("#drag").attr("offsetWidth"));
to fill the hidden field with client-side values
用客户端值填充隐藏字段
but when I do postback, the values doesn't seem to be saved.
但是当我回发时,这些值似乎没有被保存。
help
帮助
回答by Tarik
If you want to get params from the server side, you should use name instead of id attribute.
如果你想从服务器端获取参数,你应该使用 name 而不是 id 属性。
And your code should work :
你的代码应该可以工作:
$("#elementId").val("value");
回答by Martin Ongtangco
fixed it with <%= hfWidth.ClientID %>
固定它 <%= hfWidth.ClientID %>
回答by bluwater2001
in your aspx page:
在您的 aspx 页面中:
<asp:HiddenField ID="hdn_checkbox" runat="server" />
in your Javascript:
在您的 Javascript 中:
function somefunction() {
$("#<%= hdn_checkbox.ClientID %>").val("test");
}
$('.btnGreen').click(function () {
somefunction();
alert($("#<%= hdn_checkbox.ClientID %>").val());
return true;
});