javascript全局数组(javascript global array)

编程入门 行业动态 更新时间:2024-10-12 12:34:24
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 }

更多推荐

本文发布于:2023-07-26 06:27:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1271976.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   全局   javascript   global   array

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!