欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

location對象的屬性和方法應用(解析URL)

 更新時間:2013年04月12日 17:22:26   作者:  
本文將與大家分享下location對象使用屬性和方法來解析URL的實例,感興趣的朋友可以參考下,希望對你有所幫助
location對象提供了很多屬性和方法用來解析URL。
復制代碼 代碼如下:

<head>
<title></title>
<script type="text/javascript">
var uristr = window.location.search.substr(1);
var array = uristr.split('&&');
for (var i = 0; i < array.length; i++) {
var array1 = array[i].split('=');
alert(array1[0]);
}
--------------------//hash:返回#符號后的內(nèi)容
function showhash() {
alert(window.location.hash);
}
--------------------//host:服務器的名字
function showhost() {
alert(window.location.host);
}
--------------------//href:當前載入的頁面的完整的URL
function showhref() {
alert(window.location.href);
}
--------------------//pathname:url中主機名后的部分
function showpathname() {
alert(window.location.pathname);
}
--------------------//protocal:URL中使用的協(xié)議
function showprotacal() {
alert(window.location.protocal);
}
--------------------//search:執(zhí)行g(shù)et請求的URL中問號后面的部分,又稱為查詢字符串
function showsearch() {
alert(window.location.search);
}
</script>
</head>
<body>
<input type="button" value="Hash" onclick="showhash();" />
<br />
<input type="button" value="host" onclick="showhost();" />
<br />
<input type="button" value="href" onclick="showhref();" />
<br />
<input type="button" value="pathname" onclick="showpathname();" />
<br />
<input type="button" value="protocal" onclick="showprotacal();" />
<br />
<input type="button" value="search" onclick="showsearch();" />
</body>
測試search的時候,需要從另一個頁面點擊一個連接,從瀏覽器地址欄穿過來值:
<body>
<a href="HTMLPage1.htm?name='王五'&&age=22">GO</a>
</body>

相關(guān)文章

最新評論