js 子窗口赋值到父窗口

父窗口:

 

<script>
function openWin(str) {
    window.open(siteurl
+"popup/"+str, null,'width=800,height=500'); // 打开窗口

</script> 
<input type="text" id="title" name="picPath" value="<?php if(isset($pic)) {echo $pic['Path'];}?>" /> 
<href="javascript:;" onclick="openWin('searchPic');">图片</a>

 

 

子窗口:

<html>
    
<head>
        
<title>图片搜索</title>
    
</head>
    
<body>
        
<script>
            
function getValue() {
                window.opener.document.getElementById(
'title').value = document.getElementById('picPath').value // 赋值
                window.close(); // 关闭窗口
            }
        
</script>
        
<input type="text" id="picPath" />
        
<input type="button" value="确定" onclick="getValue()" />
    
</body>

</html> 

 

posted @ 2011-07-14 09:53  刘宇石  阅读(5023)  评论(0编辑  收藏  举报