从隐藏字段中获取多个值

时间:2014-03-07 13:13:48

标签: javascript asp.net

在下面的代码中,我有一个隐藏字段,它有3个值。但我只能使用javascript获取一个值。我的目标是获取所有值。 JS:

function check() {
 var hid = document.getElementById("<%= hidRegExp.ClientID %>").value;
       alert(hid);
}

asp.net:

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

1 个答案:

答案 0 :(得分:1)

var myStringArray = document.getElementById("<%= hidRegExp.ClientID %>").value.split(","); //splits by comma.

//now do something with the array. Let's write them to the console as an example
for(var i=0; i<myStringArray.length; i++)
    console.log(myStringArray[i]);

将它们分开放在字符串上。请注意,我通过简单的Google搜索找到了这个答案。当你有非常简单的问题时,有可能之前有人做过,你可以通过比等待我们为你提供答案更快的速度找到答案。