1 <!doctype html>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <title>js的location对象对url的操作</title>
6 <script>
7
8 //url处理
9 var urlHandle=[
10 {
11 name:"location.href(设置或返回完整的 URL):",
12 value:location.href
13 },{
14 name:"location.hostname(设置或返回当前 URL 的主机名):",
15 value:location.hostname
16 },{
17 name:"location.host(设置或返回主机名和当前 URL 的端口号):",
18 value:location.host
19 },{
20 name:"location.pathname(设置或返回当前 URL 的路径部分):",
21 value:location.pathname
22 },{
23 name:"location.port(设置或返回当前 URL 的端口号):",
24 value:location.port
25 },{
26 name:"location.protocol(设置或返回当前 URL 的协议):",
27 value:location.protocol
28 },{
29 name:"location.search(设置或返回从问号 (?) 开始的 URL(查询部分)):",
30 value:location.search
31 },{
32 name:"location.hash(设置或返回从井号 (#) 开始的 URL(锚)):",
33 value:location.hash
34 }
35 ];
36 for(var i=0;i<urlHandle.length;i++){
37 document.write(urlHandle[i].name+urlHandle[i].value+"<br/><br/>");
38 }
39 </script>
40 </head>
41
42 <body>
43 <form>
44 <input type="email" name="email">
45 <input type="submit" value="提交">
46 <a href="#001">从井号(#)开始的URL(锚)</a>
47 </form>
48 </body>
49 </html>
