在两个html页面之间传值小示例
2016-03-08 16:26
302 查看
最近在搞前端的一些开发,在两个页面之间进行传值,虽然搜了写资料但是不是自己想要的,因为用到了一些框架,所有内容相当于在一个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,并进行解析分割,获取相关的参数。
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,并进行解析分割,获取相关的参数。
相关文章推荐
- 在Windows 8.1的IE 11中屏蔽双击放大功能
- Apple官网研究之使用Justify布局导航
- 通过Mootools 1.2来操纵HTML DOM元素
- WEB标准网页布局中尽量不要使用的HTML标签
- Flash 与 html 的一些实用技巧
- html工作中表格<tbody>标签的使用技巧
- HTML 向 XHTML1.0 兼容性指导
- C#自写的一个HTML解析类(类似XElement语法)
- 没有文件大小限制并免费的PDF到HTML转换工具
- JavaScript与HTML结合的基本使用方法整理
- css实现气泡框效果(实例加图解)
- html链接与文本标签们
- html活用软字符连接符
- 浅谈html中id和name的区别实例代码
- HTML <!DOCTYPE> 标签
- asp中实现清除html的函数
- Android的TextView与Html相结合的具体方法
- jQuery设置和获取HTML、文本和值示例
- 『jQuery』.html(),.text()和.val()的概述及使用