JS 實現(xiàn)獲取打開一個界面中輸入的值
需求
在一個界面中打開另一個界面,通過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="調(diào)用" 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的沖突。
相關(guān)文章
移動Web中圖片自適應(yīng)的兩種JavaScript解決方法
這篇文章主要介紹了移動Web中圖片自適應(yīng)的兩種JavaScript解決方法,本文針對手機站點中的圖片自適應(yīng)問題,給出了圖集解決方法和單篇文章的解決方法,需要的朋友可以參考下2015-06-06
詳解Javacript和AngularJS中的Promises
這篇文章主要介紹了詳解Javacript和AngularJS中的Promises的相關(guān)資料,promise是Javascript異步編程很好的解決方案。,需要的朋友可以參考下2016-02-02
spirngmvc js傳遞復(fù)雜json參數(shù)到controller的實例
下面小編就為大家分享一篇spirngmvc js傳遞復(fù)雜json參數(shù)到controller的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-03-03

