您的位置:首页 > Web前端 > JavaScript

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>





内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: