问题描述
大家好,
我在Java脚本中有二维数组.单击提交按钮时,这两个二维数组必须通过服务器端.
Hi All,
I have two dimensional array in java script. these two dimensional array have to pass server side when submit button is clicked.
推荐答案
<script language="javascript">
skillArray = new Array(5)
skillArray [0] = new Array(2)
skillArray [0][0] = "Jon"
skillArray [0][1] = "DOT.NET"
skillArray [1] = new Array(2)
skillArray [1][0] = "Tim"
skillArray [1][1] = "C++"
skillArray [2] = new Array(2)
skillArray [2][0] = "Dan"
skillArray [2][1] = "C"
skillArray [3] = new Array(2)
skillArray [3][0] = "Alex"
skillArray [3][1] = "Java"
skillArray [4] = new Array(2)
skillArray [4][0] = "Robert"
skillArray [4][1] = "Perl"
var s='''';
for (i=0;i<skillarray.length;> for (j=0;j<2; j++) {
if(j==0)
s += ''"'' + skillArray[i][j] + ''"'' + '':'';
else
s += ''"'' + skillArray[i][j] + ''"'';
}
s += ",";
}
alert(s);
</script>
所以字符串看起来像
"Jon":"DOT.NET","Tim":"C ++","Dan":"C","Alex":"Java","Robert":"Perl"
用户Ajax将字符串发送到C#(后面的代码).
用户拆分功能可首先拆分主要子字符串
"Jon":"DOT.NET"
"Tim":"C ++"
"Dan":"C"
"Alex":"Java"
"Robert":"Perl"
现在使用循环来迭代每个元素,并用:"
拆分每个元素因此,您可以在C#中创建与javascript相同的二维数组.
欢呼
So the string will look like
"Jon":"DOT.NET","Tim":"C++","Dan":"C","Alex":"Java","Robert":"Perl"
User Ajax to send the string to C# (code behind).
User split function to split first the primary substring
"Jon":"DOT.NET"
"Tim":"C++"
"Dan":"C"
"Alex":"Java"
"Robert":"Perl"
Now use a loop to iterate each element and split each element with ":"
Thus you can create a 2 dimensional array in C# same as javascript.
cheers
这篇关于如何从JavaScript向服务器端发送二维数组(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!