ITeye博客

静态页面之间传值

ileson · 2010-12-08 14:42 · RIA · Web前端 · Markdown

a.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>
<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>

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。