javascript全局数组(javascript global array)
我有低于HTML代码,并尝试通过添加javascript函数向全局数组添加新值。我正在尝试像下面的方式。但它是给javascript错误。请建议任何人如何做到这一点。
<html> <head> <script> var list=[]; function getList(value){ list=list(value); } </script> </head> <body> <tr> <td> <select name="test" onchange="getList(this)"> <option id="1" value="one">One</option> <option id="2" value="two">two</option> </select> </td> </tr> <tr> <td> <select name="test1" onchange="getList(this)"> <option id="3" value="three">three</option> <option id="4" value="four">four</option> </select> </td> </tr> </body> </html>I am having below html code and trying to add new values to global array by onchanging of javascript function.I am trying to do like below way.But it is giving javascript errors.Please suggest anyone how to do this.
<html> <head> <script> var list=[]; function getList(value){ list=list(value); } </script> </head> <body> <tr> <td> <select name="test" onchange="getList(this)"> <option id="1" value="one">One</option> <option id="2" value="two">two</option> </select> </td> </tr> <tr> <td> <select name="test1" onchange="getList(this)"> <option id="3" value="three">three</option> <option id="4" value="four">four</option> </select> </td> </tr> </body> </html>最满意答案
将您的Javascript更改为以下内容
var list=new Array; ///this one way of declaring array in javascript function getList(value){ list.push(value);//push function will insert values in the list array }Change your Javascript to the following
var list=new Array; ///this one way of declaring array in javascript function getList(value){ list.push(value);//push function will insert values in the list array }更多推荐
发布评论