JS 實(shí)現(xiàn)獲取打開一個(gè)界面中輸入的值
需求
在一個(gè)界面中打開另一個(gè)界面,通過JS獲取在另一個(gè)界面中用戶輸入的值。
示例:
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>
另一個(gè)界面:
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中遇到一個(gè)問題,那就是chrome中window.close()方法不起作用。最后通過,window.opener來解決chrome和IE的沖突。
相關(guān)文章
JS實(shí)現(xiàn)的簡單輪播圖運(yùn)動效果示例
這篇文章主要介紹了JS實(shí)現(xiàn)的簡單輪播圖運(yùn)動效果,結(jié)合完整實(shí)例形式分析了javascript基于定時(shí)器動態(tài)修改頁面元素屬性的相關(guān)操作技巧,需要的朋友可以參考下2016-12-12
移動Web中圖片自適應(yīng)的兩種JavaScript解決方法
這篇文章主要介紹了移動Web中圖片自適應(yīng)的兩種JavaScript解決方法,本文針對手機(jī)站點(diǎn)中的圖片自適應(yīng)問題,給出了圖集解決方法和單篇文章的解決方法,需要的朋友可以參考下2015-06-06
詳解Javacript和AngularJS中的Promises
這篇文章主要介紹了詳解Javacript和AngularJS中的Promises的相關(guān)資料,promise是Javascript異步編程很好的解決方案。,需要的朋友可以參考下2016-02-02
spirngmvc js傳遞復(fù)雜json參數(shù)到controller的實(shí)例
下面小編就為大家分享一篇spirngmvc js傳遞復(fù)雜json參數(shù)到controller的實(shí)例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-03-03
在JavaScript中驗(yàn)證URL的新方法(2023版)
在JavaScript領(lǐng)域,URL 驗(yàn)證方面有了新消息!多年來,人們一直在討論JavaScript沒有一種簡便的方法來驗(yàn)證 URL,現(xiàn)在有了一種新方法URL.canParse(),需要的朋友可以參考下2023-09-09
bootstrap 點(diǎn)擊空白處popover彈出框隱藏實(shí)例
下面小編就為大家分享一篇bootstrap 點(diǎn)擊空白處popover彈出框隱藏實(shí)例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-01-01

