JS 实现获取打开一个界面中输入的值
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了JS 实现获取打开一个界面中输入的值,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2152字,纯文字阅读大概需要4分钟。
内容图文
需求
在一个界面中打开另一个界面,通过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 实现获取打开一个界面中输入的值所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。