您的位置:首页 > 其它

父子页面传值

2013-12-16 12:52 197 查看
父页面:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>parent.html</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script type="text/javascript">
function openWin() {
var style = "width=300,height=400,location=no,directories=no,toolbar=no,status=no,menubar=no,resizable=no,scrollbars=no";
window.open("child.html","open other window",style);
}

function setValue(name,hname) {
document.getElementById("name").value = name;
document.getElementById("hname").value = hname;
}
</script>
</head>
<body>
name:<input type="text" id="name"/><a href="#" onclick="openWin()">please click it</a>
<input type="hidden" name="name" id="hname"/>
</body>
</html>

子页面

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>child.html</title>

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">

<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script type="text/javascript">
function selectedThis(obj) {
var name = obj.value;
var hname = obj.id;
window.opener.setValue(name,hname);
//调用父窗口的方法进行传值
window.opener = null;
window.close();
}
</script>
</head>

<body>
请选择名称:<br/>
<input type="radio" name="name" id="name1" value="名称1" onclick="selectedThis(this)"/>名称1
<input type="radio" name="name" id="name2" value="名称2" onclick="selectedThis(this)"/>名称2
<input type="radio" name="name" id="name3" value="名称3" onclick="selectedThis(this)"/>名称3
<br/>
<input type="radio" name="name" id="name4" value="名称4" onclick="selectedThis(this)"/>名称4
<input type="radio" name="name" id="name5" value="名称5" onclick="selectedThis(this)"/>名称5
<input type="radio" name="name" id="name6" value="名称6" onclick="selectedThis(this)"/>名称6

</body>
</html>








总结:这个在360浏览器中测试不理解,但在IE可以测试成功。在父页面中主要写入

window.open("child.html","open other window",style);


function setValue(name,hname)
在子页面中调用父类的方法
window.opener.setValue(name,hname);
//调用父窗口的方法进行传值
window.opener = null;
window.close();






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