作家
登录

JS 实现获取打开一个界面中输入的值

作者: 来源:www.28hudong.com 2013-03-29 23:05:33 阅读 我要评论

需求在一个界面中打开另一个界面,通过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文本框不能输入空格验证方法

1、只是不能输入空格复制代码 代码如下:<input type="text" onkeyup="this.value=this.value.replace(/^ +| +$/g,'')">2、不能输入空格及英文状态下的逗号复制代码 代码如下: <input type="text" onkeyup="this.va>>>详细阅读


本文标题:JS 实现获取打开一个界面中输入的值

地址:http://www.17bianji.com/kaifa2/JS/22195.html

关键词: 探索发现

乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

网友点评
自媒体专栏

评论

热度

精彩导读
栏目ID=71的表不存在(操作类型=0)