Posted on 2007-11-16 14:52
瘋狂 閱讀(1990)
評論(2) 編輯 收藏
今天寫項目的時候用到了需要從另一個打開頁面取值的javascript,覺得很有用,就把它簡化成了一個簡單的例子貼出來,有小區的可以看看,有誰有更好的給小弟仍一個。
用兩個頁面進行測試:
1,訪問頁面:a.html:
<html>
<head>
</head>
<body>
<input type="text" name="name" id="name" >
<input type="button" value="選擇用戶"
onclick="window.open('b.html','selectname',800,600,1);">
</body>
</html>
2,新打開的選擇頁面b.html
<html>
<head>
<script type="text/javascript">
function selectOrg(name){
if(window.opener){
window.opener.document.all.name.value =name;
window.close();
}
}
</script>
</head>
<body>
<input type="radio" name="name" onclick="selectOrg('李四')">李四
<input type="radio" name="name" onclick="selectOrg('張三')">張三
<input type="radio" name="name" onclick="selectOrg('王五')">王五
</body>
</html>
試一下吧!