在下面的代码中,我有一个隐藏字段,它有 3 个值。但是我只能使用 javascript 获取一个值。我的目标是获取所有值。 JS:
function check() {
var hid = document.getElementById("<%= hidRegExp.ClientID %>").value;
alert(hid);
}
asp.net:
<asp:HiddenField ID="hidRegExp" runat="server" >
</asp:HiddenField >
最佳答案
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]);
只需将它们分成字符串即可。请注意,我通过简单的谷歌搜索找到了这个答案。当您遇到非常简单的问题时,很可能有人已经做过,您可以通过搜索更快地找到答案,而不是等待我们为您提供答案。
关于javascript - 从隐藏字段获取多个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22251073/