簡體   English   中英

將值從html作為數組傳遞給javascript

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM