JS 实现获取打开一个界面中输入的值
需求
在一个界面中打开另一个界面,通过JS获取在另一个界面中用户输入的值。
示例:
Index.html
<html><head>
<meta http-equiv="content-type" content="text/html; charset=gbk">
<title>主页</title>
<script type="text/javascript">
function EntryPoint() {
var style = 'dialogHeight:600px;dialogWidth:800px;status:no;help:0;scrool:yes';
var a = window.showModalDialog('other.html', '', style);
if (a == undefined) {
a = window.returnValue;
}
// debugger;
if (a != null && a.length > 0) {
document.getElementById("name").value = a[0];
document.getElementById("age").value = a[1];
}
}
</script>
</head>
<body>
<input type="button" value="调用" onclick="EntryPoint()"/><br/>
<input type="text" name="name" id="name" /><br/>
<input type="text" name="age" id="age" />
</body>
</html>
另一个界面:
other.html
<html><head>
<title>操作界面</title>
<meta http-equiv="content-type" content="text/html; charset=gbk">
<script type="text/javascript">
function postValue() {
var name = document.getElementById("name").value;
var age = document.getElementById("age").value;
var a = new Array();
a[0] = name;
a[1] = age;
//debugger;
if (window.opener != undefined) {
//for chrome
window.opener.returnValue = a;
}
else {
window.returnValue = a;
}
window.close();
}
</script>
</head>
<body>
<input type="button" value="确定" onclick="postValue();"/><br/>
名字:<input type="text" name="name" id="name" /><br/>
年龄:<input type="text" name="age" id="age" />
</body>
</html>
在该DEMO中遇到一个问题,那就是chrome中window.close()方法不起作用。最后通过,window.opener来解决chrome和IE的冲突。
- JS 实现获取打开一个界面中输入的值
- JS 实现获取打开一个界面中输入的值
- js实现文本框中输入文字页面中div层同步获取文本框内容的方法
- xcode 在一个界面中打开多个子界面,实现跳转不影响
- android 调用系统相册选取照片或者打开相机拍照获取图片,返回时为什么会回到home界面或者到前一个界面,然后才会跳转到当前activity
- js:页面多处输入只使用一个验证码/获得焦点显示/onblur隐藏实现
- 如何用JS实现打开一个页面自动定位到某一行
- 编写一个jsp程序,实现用户登录,当用户输入的用户或密码错误时,将页面重定向到错误提示页,并在该页面显示30秒后 自动回到用户登录界面
- js实现获取当前月份前的12个月份,格式化后放在一个数组里。
- js实现一个链接打开两个链接地址的方法
- Js屏蔽按住键盘不停输入内容的问题,实现按住也只能输入一个字符
- 请教一个KEYDOWN的处理,想实现输入符A,但面界面上出现B(想实现在英文键盘输入其它语言的字符),重载了CEdit,但不会没出现我要的效果?
- 让按钮在输入法之上显示,实现一个优雅的登陆界面
- 【JS】:JS实现的一个网页输入然后输出加和的网页
- 如何用js实现,在一个页面有个输入文档框,然后点击查询按扭后,调用IE的查询功能在当前页面进行查询
- VC++界面编程之--实现一个画板并提供文字输入功能(MsPaint)
- js实现输入一个数组,实现数组元素能够组成的最大整数
- 用Js Dom实现通过用户输入行数和列数,生成一个表格
- [置顶] Android开发之使一打开activity等界面Edittext获取焦点,弹出软键盘java代码实现
- JS实现是一个文本框(值为参数)输入另一个显示(查询结果)