匿名用户
1级
2015-05-17 回答
1. location是浏览器内置对象,不能自己定义名为location的变量。
2. 变量名中不能包含"-"符号
3. 数组下标从0开始
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>获取URL</title>
</head>
<body>
<script type="text/javascript">
Mylocation = {};
Mylocation.search = '?username=789&mobienumber=789';
alert(Mylocation.search);
function relocationa()
{
alert(Mylocation.search);
}
function geturlinf()
{
var str=Mylocation.search;
var words=str.split('&');
var words1Len=words[0].length;
var words2Len=words[1].length;
alert(words[0].substring(10,words1Len));
alert(words[1].substring(12,words2Len));
}
</script>
<input type="button" value="再看一遍" οnclick="relocationa()" /></br>
<input type="button" value="弹出文本框信息" οnclick="geturlinf()" /></br>
</body>
</html>