[英]pass value from html to javascript as array
我编写了一个代码,该代码提供了来自数据库的值并将其保存在列表中,然后将列表放入数组中并将其发送到ASP hiddenField。 我想将此数据作为数组传递给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脚本数组:
我假设您正在获取hdnCity_BillMonth值,例如“ city1,city2,city3,... cityN”
var City_BillMounth = [];
City_BillMounth = hdnCity_BillMonth.split(",");
console.log("city Array: "+ City_BillMounth );
对hdnCount_BillMount
也是如此。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.