In the use of JS programming, sometimes you need to return two or more than two data in a method, the following methods can be implemented:
1 Use the array in the following way:
<HTML><Head> <title>The JS function returns multiple values--oec2003</title></Head><Body> <inputtype= "button"onclick= "GetNames ()"value= "Test" /> <Scripttype= "Text/javascript">functionGetData () {varnames=NewArray ("oec2003","oec2004"); returnnames;}functionGetNames () {varnames=GetData (); Alert (GetData () [0]); //back to oec2003}</Script></Body></HTML>
2 encapsulate the data in JSON and return it as follows:
<HTML><Head><title>The JS function returns multiple values--oec2003</title></Head><Body><inputtype= "button"onclick= "GetInfo ()"value= "Test"/><Scripttype= "Text/javascript">functionGetData () {varInfo={"name":"oec2003"," Age":" -"}; returninfo;}functionGetInfo () {varInfo=GetData (); varname=info["name"]; var Age=info[" Age"]; Alert ("Name:"+name+"Age:"+Age );}</Script></Body></HTML>
For a more detailed introduction to JSON, see here
3 This is the simplest way to look at the following code:
<HTML><Head><title>The JS function returns multiple values--oec2003</title></Head><Body><inputtype= "button"onclick= "GetInfo ()"value= "Test"/><Scripttype= "Text/javascript"> functionGetData () {return ["oec2003", -] } functionGetInfo () {varInfo=GetData (); Alert ("Name:" +info[0] + "Age:" +info[1]); }</Script></Body></HTML>
Article from: http://www.cnblogs.com/oec2003/archive/2009/12/11/1621775.html
Three ways to return multiple values in the JS method