使用JQuery更新隐藏字段

时间:2014-04-28 16:07:18

标签: javascript jquery asp.net hidden-field

所有

点击一个复选框后,我有以下代码更新我的aspx页面中隐藏字段的文本:

BiopsyDone:

< asp:CheckBox ID ="cbLiverBiopsy" runat="server" Checked="false" OnCheckedChanged="BiopsyResults_SelectedIndexChanged"/> <br/>
    < asp:HiddenField ID="hide" runat="server" Value=" " /> 

 < script>

        $(document).ready(function () {
            $("#cbLiverBiopsy").change(function () {
                $("#hide").val("The liver biopsy results were ");
            });
        });

    </script>

程序运行后,单击复选框后隐藏字段不会更新。有什么建议吗?

谢谢, 艾伦

3 个答案:

答案 0 :(得分:5)

使用ClientID进行此操作的方法

$('#<%= hide.ClientID %>').val("The liver biopsy results were ");

然后它不需要是静态的

答案 1 :(得分:1)

为隐藏输入设置clientidmode="static" ..

< asp:HiddenField ID="hide" runat="server" Value=" " clientidmode="static"/>

将其作为..

访问
document.getelementid('hide').value="The liver biopsy results were";

$('#<%= hide.ClientID %>').val("The liver biopsy results were ");

答案 2 :(得分:0)

按ID获取

<强> HTML:

 < asp:HiddenField ID="hide" runat="server" Value=" " /> 

<强> jQuery的:

$('#<%= hide.ClientID %>').val("The liver biopsy results were ");

按类别获取

<强> HTML:

 < asp:HiddenField ID="hide" class="hideClass" runat="server" Value=" " /> 

<强> jQuery的:

$('.hideClass').val("The liver biopsy results were ");