 
		路途7
2017-03-11 15:01
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>location</title>
</head>
<script type="text/javascript">
var kl=[protocol,host,pathname,search,hash];
var num;
for(num=0;num<=4;num++)
{
document.write(location.(kl[num]);
}
</script>
<body>
</body>
</html>
 
				错误1:数组中的项都是location对象的属性,形式上应写为:location.protocol等等;
错误2:for循环本身写得有问题;如果你想这么写,那么上面的数组中应该全是字符串属性,那样的话应写为:["protocol","host"]等等。
以上
 
				document.write(location.(kl[num]);少了kuohao
 
				其实也可以写成这样:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>location</title>
</head>
 <script type="text/javascript">
 var kl=[location.protocol,location.host,location.pathname,location.search,location.hash];
  for(var num=0;num<=4;num++)
  {
      document.write(kl[num]+"<br>");
  }
 </script>
<body>
</body>
</html>
JavaScript进阶篇
469067 学习 · 22582 问题
相似问题