---
title: "静态页面之间传值"
author: "ileson"
date: "2010-12-08T14:42:35Z"
tags: []
categories: ["Web前端"]
slug: "untitled"
draft: false
lastmod: "2010-12-08T16:20:05Z"
id: 836674
url: "https://ileson.iteye.com/blog/836674"
---

a.html

```html
<html>
<head>
<script>
function setData(){
    var ucode=document.forms[0].usercode.value;
    var url="b.html?usercode="+ucode;
    window.location.href=url;/*把url放到地址栏中*/
}
</script>
</head>
<body>
    <form >
    <input type="text" value="" name="usercode" />
    <input type="button" value="传值" onclick="setData();" />
    </form>
</body>
</html>
```


b.html

```html
<html>
<head>
<script>
function getData(){
    var url=window.location.href;//得到地址栏中的url字符串。
    var usercode=url.split("=")[1];
    alert(usercode);
}
</script>
</head>
<body>
    <input type="button" value="得值" onclick="getData();" />
</body>
</html>
```