實現案列:在A頁面點擊按鈕,彈框進入B頁面,點擊B頁面下拉框,關閉窗體,並將選中的值返回到A頁面!
A頁面代碼:
<html> <head> <meta charset="utf-8"> <title></title> <script src="js/jquery-1.10.2.min.js"></script> <script> function openWin() { var name; //網頁名稱,可為空; var iWidth = "800"; //彈出窗口的寬度; var iHeight = "800"; //彈出窗口的高度; var iTop = (window.screen.availHeight - 30 - iHeight) / 2; //獲得窗口的垂直位置; var iLeft = (window.screen.availWidth - 10 - iWidth) / 2; //獲得窗口的水平位置; var win = window.open("B.html", name, 'height=' + iHeight + ',,innerHeight=' + iHeight + ',width=' + iWidth + ',innerWidth=' + iWidth + ',top=' + iTop + ',left=' + iLeft + ',toolbar=no,menubar=no,scrollbars=auto,resizeable=no,location=no,status=no'); } function sele(NO) { //NO為返回值 $("#txtName").val(NO); } </script> </head> <body> <input type="text" id="txtName" onclick="openWin()"/> </body> </html>
B頁面代碼:
<html> <head> <meta charset="utf-8"> <title></title> <script src="js/jquery-1.10.2.min.js"></script> <script> function getvalue(v) { window.opener.sele(v); window.close(); } </script> </head> <body> <select id="test" onchange="getvalue(this.options[this.options.selectedIndex].value)"> <option value="1">文本1</option> <option value="2">文本2</option> <option value="3">文本3</option> <option value="4">文本4</option> <option value="5">文本5</option> </select> </body> </html>
完美解決!