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

location對(duì)象的屬性和方法應(yīng)用(解析URL)

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

<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:返回#符號(hào)后的內(nèi)容
function showhash() {
alert(window.location.hash);
}
--------------------//host:服務(wù)器的名字
function showhost() {
alert(window.location.host);
}
--------------------//href:當(dāng)前載入的頁(yè)面的完整的URL
function showhref() {
alert(window.location.href);
}
--------------------//pathname:url中主機(jī)名后的部分
function showpathname() {
alert(window.location.pathname);
}
--------------------//protocal:URL中使用的協(xié)議
function showprotacal() {
alert(window.location.protocal);
}
--------------------//search:執(zhí)行g(shù)et請(qǐng)求的URL中問(wèn)號(hào)后面的部分,又稱(chēng)為查詢(xún)字符串
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>
測(cè)試search的時(shí)候,需要從另一個(gè)頁(yè)面點(diǎn)擊一個(gè)連接,從瀏覽器地址欄穿過(guò)來(lái)值:
<body>
<a href="HTMLPage1.htm?name='王五'&&age=22">GO</a>
</body>

相關(guān)文章

最新評(píng)論