注册 登录
编程论坛 JavaScript论坛

数组的length怎么会不存在呢??

拒绝飞翔的燕 发布于 2009-11-14 20:44, 746 次点击
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript" type="text/javascript" >
var numnames=0;
var names= new Array();

function w(){

document.theform.newname.value=names[numnames];

numnames++;
names.sort();
document.theform.sorted.value=names.join("=");
}
</script>
</head>

<body>
<h1>按顺序排列数组</h1>
<form id =" theform" method="post" action="">
name:
<input type="text" name="newname" size="20"/>
<input type="button" value="点击" onclick="w()"/>
<br/>
<h3>名字排序</h3>
<textarea cols="60" rows="10" name="sorted">
the sorted names will qppear here.
</textarea>
</form>
</body>
</html>
3 回复
#2
aspic2009-11-15 08:57
程序代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. xmlns="http://www. http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>

<body>
<h1>按顺序排列数组</h1>
<form id="theform" name="theform" method="post" action="">
    name:<input type="text" name="newname" size="20"/><input type="button" value="点击" onclick="w()"/><br/>
    <h3>名字排序</h3>
    <textarea cols="60" rows="10" name="sorted">the sorted names will qppear here.</textarea>
</form>
<script language="javascript" type="text/javascript" >
var numnames = 0;
var names = document.theform.sorted.value.split(' ');
function w() {
    document.theform.newname.value = names[numnames];
    numnames++;
    names.sort();
    document.theform.sorted.value = names.join("--->")
}
</script>
</body>
</html>
应该类似这样吧
#3
aspic2009-11-15 09:02
但是不知道你 name:<input type="text" name="newname" size="20"/>这个用来干嘛的
#4
niusanjs2012-08-24 10:24
你的这句document.theform.newname.value=names[numnames];
应该改为names[numnames]=document.forms[0].newname.value;
因为你是要给数组赋值.
1