How to get public array In HTML file which is initialize in .cs file of web app?
Рow to get the array in HTML file added from some side initialize in .cs file? Hope for your rep开发者_如何学JAVAly.
Your question does not provide enough info. I will assume you mean the codebehind file (c#) when you say .cs file (what else is there to assume?) and your array is added in c#, which you want to access in js
Register your array as a string literal as script block
something like:
string myArr = "; var myArr = [ 1, 2, 3, 4 ]; "; //putting your array in a string
ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), myArr, true);
now in your html file, you can access them with javascript.
<script type="text/javascript">
alert(myArr[2]); //will alert 3
</script>
For 2D arrays,
var myArr = [[0,0],[1,1],[2,2]]; //2D array
alert(myArr[0]); // to access 1st row: [0,0]
alert(myArr[0][0]); // to access 1st row 1st column: 0
- Send array (via GET) as comma separated list, e.g.
Static.html?arr=1,2,3,4
- Read query string using JavaScript, e.g. jQuery Query Object
- Parse it into an array, e.g. string.split()
精彩评论