古詩詞大全網 - 成語用法 - JS用split截取字符串並彈出,函數不工作

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>