[收藏]如何把客户端的 JS 数组传到服务器端
把数组在客户端付给一<input type ="hidden" id ="hidden1" runat="server"/>,再button的事件里可以获得
可以在数组元素间插入特殊的记号进行分割,到服务端再split开来
具体代码如下:
<INPUT id="hidden1" type="hidden" runat="server" NAME="hidden1">
<asp:Button id="Button1" runat="server" Text="获得客户端的数组"></asp:Button>
<P></P>
<script>
var array1 = new Array();
array1[0] ="你";
array1[1] = "我";
array1[2] ="他";
document.all.hidden1.value = array1;
</script>
<asp:Button id="Button1" runat="server" Text="获得客户端的数组"></asp:Button>
<P></P>
<script>
var array1 = new Array();
array1[0] ="你";
array1[1] = "我";
array1[2] ="他";
document.all.hidden1.value = array1;
</script>
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim str As String
Dim sArr As String()
str = hidden1.Value
sArr = str.Split(",")
str = ""
For Each str In sArr
Response.Write("<br>数组值:" + str)
Next
End Sub
Dim str As String
Dim sArr As String()
str = hidden1.Value
sArr = str.Split(",")
str = ""
For Each str In sArr
Response.Write("<br>数组值:" + str)
Next
End Sub