JavaScript浏览器编程之——使用URL传递参数

  default.css:
body {
    background-color:#F0FFF0;
}

  blue.css:

body {
    background-color:blue;
}
  red.css:
body {
    background-color:red;
}

 

  white.css:
body {
    background-color:white;
}

 

  ex9.html:
代码
 1 <html>
 2 <head>
 3 <title>URL参数传递</title>
 4 <style type="text/css">
 5     * {margin:0}
 6     body {text-align:center;min-width:760px}
 7     div {padding:3px 3px 3px 3xp}
 8     #main {width:360px;margin:0 auto;text-align:left;margin-top:30px}
 9 </style>
10 
11 <script type="text/javascript">
12     // URL参数
13     var search = document.location.search;
14     if(!search && search.length == 0) {
15         search = "default";
16     } else {
17         search = search.substring(1,search.length);
18     }
19     // 动态加载样式表
20     var style = "<link href='" + search + ".css' rel='stylesheet' />";
21     document.write(style);
22 </script>
23 </head>
24 <body>
25     <div id="main">
26         <div><href="ex9.html">默认</a></div>
27         <div><href="ex9.html?blue">蓝色</a></div>
28         <div><href="ex9.html?red">红色</a></div>
29         <div><href="ex9.html?white">白色</a></div>
30     </div>
31 </body>
32 </html>

 

posted @ 2010-02-03 11:09  MikeLin  阅读(397)  评论(0编辑  收藏  举报