javascript - 将值作为数组从 html 传递到 javascript

标签 javascript asp.net arrays vb.net

我编写了一段代码,从数据库中获取值并将它们保存在列表中,然后将列表放入数组中并将其发送到 ASP hideField。 我想将此数据作为数组传递给 JavaScript var。我该怎么做? 我想将值保存为数组中的字符串。

aspx:

<asp:HiddenField ID="hdnCity_BillMonth" runat="server" />
<asp:HiddenField ID="hdnCount_BillMount" runat="server" />

aspx.vb:

 hdnCity_BillMonth.Value = String.Join(",", City)
 hdnCount_BillMount.Value = String.Join(",", Value)

城市和值是列表

 var City_BillMounth ;
 var Count_BillMounth;

最佳答案

由于您使用“,”符号连接城市值,因此您可以使用 split 轻松将其转换为 Java 脚本数组,如下所示:

I assume you are getting your hdnCity_BillMonth values like "city1, city2,city3,...cityN"

 var City_BillMounth = [];
 City_BillMounth = hdnCity_BillMonth.split(",");
 console.log("city Array: "+ City_BillMounth );

hdnCount_BillMount 也执行相同的操作。

关于javascript - 将值作为数组从 html 传递到 javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30420577/

相关文章:

asp.net - 与 ASP.NET 项目中的网页设计师协作(使用 SVN)

c# - 动态加载用户控件

asp.net - 如何隐藏 ASP.NET ChangePassword 控件上的取消按钮

c - 打印 C 中结构数组中每个结构成员的函数

c++ - 索引 wchar_t 数组中的字符

javascript - react Jest enzyme : testing callback of child component that calls another function first before calling the callback

javascript - 设置定时器为slidedown,按钮在slideup后改变

arrays - 有没有什么有效的简单方法可以用 Mathematica 比较两个长度相同的列表?

javascript - 在 Bootstrap 网站中包含动态/移动背景

javascript - 使用javascript对结果进行编号时如何用字母代替数字