繁体   English   中英

如何获取由jquery / javascript更新的隐藏字段值代码背后

[英]How to get hidden field value code behind updated by jquery/javascript

我有一个<asp:menu/>控件和一个隐藏字段。现在我正在使用jQuery来更改隐藏字段的值。 代码是:-

$(function() {

    $(".primaryStaticMenu  tr,td").each(function(index) {

        $(this).click(function() {

            if ($(this).attr("title") != "undefined"
                && $(this).attr("title").length > 0) {

                document.getElementById('ctl00_Hidden_Master_Location').value = $(this).attr("title");

                alert(document.getElementById('ctl00_Hidden_Master_Location').value);
                //return false;
            }
        });
    });
});

获取更新值的服务器端代码是:

string Get_cng_value = Hidden_Master_Location.Value;

但是Hidden_Master_Location.Value每次都显示null 谁能告诉我如何从后面的代码中获取隐藏字段的更新值。

假设您的隐藏字段是..

<asp:HiddenField ID="Hidden_Master_Location" runat="server"  />

你可以在jquery中获取hidden file的值作为

var locationValue= $("#<%= Hidden_Master_Location.ClientID %>").val();

这样做对我有用。诀窍是将隐藏字段的珍贵ID保存在另一个隐藏输入字段中,然后使用该隐藏值将其重新构建。

标记

<asp:HiddenField ID="HiddenFieldMaster" runat="server" />
   <input type="hidden" id="inputHidden" value='<%= HiddenFieldMaster.ClientID%>' />

Javascript

    $(function() {

$(".primaryStaticMenu  tr,td").each(function(index) {

    $(this).click(function() {

        if ($(this).attr("title") != "undefined"
            && $(this).attr("title").length > 0) {

           var inputHidden = document.getElementById('inputHidden');
                $("#" + inputHidden.value).val($(this).attr("title"));

            alert(inputHidden.value);
            //return false;
        }
    });
});
 });

背后的代码

String Get_cng_value = HiddenFieldMaster.Value;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM