JS 实现获取打开一个界面中输入的值
2013-03-19 00:00
531 查看
需求
在一个界面中打开另一个界面,通过JS获取在另一个界面中用户输入的值。
示例:
Index.html
另一个界面:
other.html
在该DEMO中遇到一个问题,那就是chrome中window.close()方法不起作用。最后通过,window.opener来解决chrome和IE的冲突。
在一个界面中打开另一个界面,通过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实现,在一个页面有个输入文档框,然后点击查询按扭后,调用IE的查询功能在当前页面进行查询
- Java类中获取文件的方式以及实现一个类似js中的eval函数
- 编写一个jsp程序,实现用户登录,当用户输入的用户或密码错误时,将页面重定向到错误提示页,并在该页面显示30秒后 自动回到用户登录界面
- js:页面多处输入只使用一个验证码/获得焦点显示/onblur隐藏实现
- js实现在文本框输入一个百分数,另一个数跟着动态变化(只允许输入0-100的整数)【支持IE浏览器】
- js实现获取当前月份前的12个月份,格式化后放在一个数组里。
- js实现输入一个数组,实现数组元素能够组成的最大整数
- Js屏蔽按住键盘一直输入的问题,实现按住也只能输入一个字符
- js获取input标签的输入值实现代码
- JS实现是一个文本框(值为参数)输入另一个显示(查询结果)
- 用Js Dom实现通过用户输入行数和列数,生成一个表格
- 如何用JS实现打开一个页面自动定位到某一行
- js实现一个链接打开两个链接地址的方法
- 【JS】:JS实现的一个网页输入然后输出加和的网页
- 一个简单的node.js界面实现方法
- 用js实现输入一个链表,输出该链表中倒数第k个结点。
- android 调用系统相册选取照片或者打开相机拍照获取图片,返回时为什么会回到home界面或者到前一个界面,然后才会跳转到当前activity
- VC++界面编程之--实现一个画板并提供文字输入功能(MsPaint)