在两个html页面之间传值小示例

来源:互联网 发布:如何关闭linux系统 编辑:程序博客网 时间:2024/06/06 09:15

最近在搞前端的一些开发,在两个页面之间进行传值,虽然搜了写资料但是不是自己想要的,因为用到了一些框架,所有内容相当于在一个html中,与普通的两个独立的html页面直接的传递值的方法不太一样,记之,以备用。

a.html 如下:

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>New Document</title>    <script>      function   to(){        var  getval =document.getElementById("cc").value;        window.location.href="b.html?cc="+getval;      }    </script></head><body><input type="text" id ="cc" > <input type="button"  value="a"  onclick="to()" ></body></html>
b.html如下:

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Title</title>    <script>  var thisURL = document.URL;  var  getval =thisURL.split('?')[1];  var showval= getval.split("=")[1];  function  showvalf(){     alert(showval);     document.getElementById('ee').value=showval;  }</script></head><body onload="showvalf()"><input type="text"  id ="ee" /></body></html>

原理是解析当前页面的url,并进行解析分割,获取相关的参数。






1 0
原创粉丝点击