JavaScript子文本传到父文本框显示
2016-03-15 19:39
399 查看
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<script type="text/javascript">
function fun(){
window.open("sub.html");
}
</script>
<body>
<input type="text" id="txt">
<input type="button" id="button" value="打开sub窗口" onclick="fun()">
</body>
</html>
//sub.html文件
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<script type="text/javascript">
function fun(){
//1.拿到文本框中填写的数据
var v=document.getElementById("subTxt").value;
//2.拿到父框口对象
var w=window.opener;
//3.拿到父窗口中的文本框对象
var txt=w.document.getElementById("txt");
//4.将内容赋值给父窗口中的文本框对象的value属性
txt.value=v;
}
</script>
<body>
<input type="text" id="subTxt">
<input type="button" id="sunButton" value="向父窗口传值"onclick="fun()">
</body>
</html>
![](http://img.blog.csdn.net/20160315193752887?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
![](http://img.blog.csdn.net/20160315193803912?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<script type="text/javascript">
function fun(){
window.open("sub.html");
}
</script>
<body>
<input type="text" id="txt">
<input type="button" id="button" value="打开sub窗口" onclick="fun()">
</body>
</html>
//sub.html文件
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<script type="text/javascript">
function fun(){
//1.拿到文本框中填写的数据
var v=document.getElementById("subTxt").value;
//2.拿到父框口对象
var w=window.opener;
//3.拿到父窗口中的文本框对象
var txt=w.document.getElementById("txt");
//4.将内容赋值给父窗口中的文本框对象的value属性
txt.value=v;
}
</script>
<body>
<input type="text" id="subTxt">
<input type="button" id="sunButton" value="向父窗口传值"onclick="fun()">
</body>
</html>
相关文章推荐
- 通用JSON生成器3
- JavaScript节点属性
- 用JS控制图片随鼠标移动
- js 数组定义与常用函数小结
- JavaScript系列:模块化与链式编程
- SWFUpload 和Extjs3.3 + swfUpload2.2 实现多文件上传组件
- JavaScript系列:函数调用方式
- js验证表单
- JS技巧
- js如何从循环跳出方法
- Extjs 打包 failed to find any files
- Jsoup 文档
- JS实现星级评分
- IE8-下trim()函数不可用的问题解决
- jstorm操作命令
- JStorm之Supervisor简介
- JStorm介绍
- JavaScript事件绑定与删除
- javascript之typeof、constructor、instanceof
- JavaScript-4.1-简单的表单操作,函数用法---ShinePans