<html>
<head>
<title>主页面(父页面)</title>
<script language="javascript" type="text/javascript">
function onc(){
var someValue=window.showModalDialog("b.html","","dialogWidth=500px;dialogHeight=500px;status=no;help=no;scrollbars=no");
var arr=someValue.split("/");
document.form1.p1t.value=arr[0];
document.form1.p2t.value=arr[1];
}
</script>
</head>
<body>
<form name="form1" action="#">
<input type="text" name="p1t">
<input type="text" name="p2t">
<input type="button" value="打开对话框" οnclick="onc()">
</form>
</body>
</html>
<html>
<head>
<title>子页面</title>
<script language="javascript" type="text/javascript"&g
js将子页面的值返回给父页面
最新推荐文章于 2020-12-09 14:06:24 发布
该博客介绍了如何使用JavaScript在子页面(b.html)中获取用户输入并将其值返回到父页面。通过`showModalDialog`函数打开子页面,并在子页面中定义函数`a()`,当用户点击‘传值’按钮时,将输入值与固定字符串拼接,然后通过`parent.window.returnValue`将结果传回父页面。在父页面中,使用`onc()`函数接收返回值并更新表单字段。
摘要由CSDN通过智能技术生成