JS用split截取字符串并弹出,函数不工作

location是浏览器内置对象,不能自己定义名为location的变量。

变量名中不能包含"-"符号

数组下标从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="再看一遍" onclick="relocationa()" /></br>

<input type="button" value="弹出文本框信息" onclick="geturlinf()" /></br>

</body>

</html>