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)文章
javascript實現(xiàn)youku的視頻代碼自適應(yīng)寬度
這篇文章主要介紹了javascript實現(xiàn)youku的視頻代碼自適應(yīng)寬度的方法的示例,十分的簡單實用,有需要的小伙伴可以參考下。2015-05-05JavaScript中判斷數(shù)據(jù)類型的方法總結(jié)
這篇文章主要為大家詳細(xì)介紹了一些JavaScript中判斷數(shù)據(jù)類型的方法,文中的示例代碼講解詳細(xì),具有一定的學(xué)習(xí)價值,需要的小伙伴可以了解一下2023-07-07eslint+prettier統(tǒng)一代碼風(fēng)格的實現(xiàn)方法
這篇文章主要介紹了eslint+prettier 統(tǒng)一代碼風(fēng)格的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07AngularJS實現(xiàn)textarea記錄只能輸入規(guī)定數(shù)量的字符并顯示
AngularJS 是一個 MV* 框架,最適于開發(fā)客戶端的單頁面應(yīng)用。它不是個功能庫,而是用來開發(fā)動態(tài)網(wǎng)頁的框架。接下來通過本文給大家介紹AngularJS實現(xiàn)textarea記錄只能輸入規(guī)定數(shù)量的字符并顯示的相關(guān)內(nèi)容,需要的朋友參考下吧2016-04-04