这只是根据需要把数组转化成字符串(用,链接) 或把 比较特殊的字符串(中间有分割符,如例子中的,) 转化成 数组<link rel="stylesheet" href="css/PublicStyle.css" type="text/css" />
<link rel="stylesheet" href="css/WorkAreaStyle.css" type="text/css" />
<title>无标题文档 </title>
</head><body><input id="xxx" type="hidden" value="" />
<input id="btn" type="button" value="test hd" onclick="test(1);" /> <!--主动调用--></body>
<script language="javascript" type="text/javascript">
var a="123,456,789" //字符串
var b=[123,456,789] //数组
//alert(a)
if ( typeof a == "string" ){
//如果是,则用逗号分割该字符串,构造出一个数组
a = a.split(",");
}
alert(a.length) //a转化成 数组
if( b.constructor == Array ){
//如果是,则用逗号连接该数组,得到一个字符串
b = b.join(',');
}
alert(b)//转化成字符串
</script>
</html> [/code]
<link rel="stylesheet" href="css/WorkAreaStyle.css" type="text/css" />
<title>无标题文档 </title>
</head><body><input id="xxx" type="hidden" value="" />
<input id="btn" type="button" value="test hd" onclick="test(1);" /> <!--主动调用--></body>
<script language="javascript" type="text/javascript">
var a="123,456,789" //字符串
var b=[123,456,789] //数组
//alert(a)
if ( typeof a == "string" ){
//如果是,则用逗号分割该字符串,构造出一个数组
a = a.split(",");
}
alert(a.length) //a转化成 数组
if( b.constructor == Array ){
//如果是,则用逗号连接该数组,得到一个字符串
b = b.join(',');
}
alert(b)//转化成字符串
</script>
</html> [/code]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<link rel="stylesheet" href="css/PublicStyle.css" type="text/css" />
<link rel="stylesheet" href="css/WorkAreaStyle.css" type="text/css" />
<title>无标题文档 </title>
</head><body><input id="xxx" type="hidden" value="" />
<input id="btn" type="button" value="test hd" onclick="test(1);" /> <!--主动调用--></body>
<script language="javascript" type="text/javascript">
var a="123,456,789" //字符串
var b=[123,456,789] //数组
//alert(a)
if ( typeof a == "string" ){
//如果是,则用逗号分割该字符串,构造出一个数组
a = a.split(",");
}
alert(a.length) //a转化成 数组
if( b.constructor == Array ){
//如果是,则用逗号连接该数组,得到一个字符串
b = b.join(',');
}
alert(b)//转化成字符串
</script>
</html>