子窗口调父窗口对象

用javaScript操作两个页面
在新窗口中添加内容到父窗口

代码如下:
父窗口: form.html
< script language = " JavaScript " >
function  addItems() 
{
    
var  AWnd = window.open('items.htm','fwId','resizable = yes,scrollbars = yes,width = 300 ,height = 400 ');
    AWnd.focus();

}
function  delItems() 
{
  
var  sel = document.menu.fwId;
  
for (i = 0 ;i <= sel.options.length;i ++ )
  {
  
if (sel.options[i] != null )
    
if (sel.options[i].selected)
    {
      sel.options[i]
= null ;
      i
-- ;
    }
  }
}
</ script >

< form method = " post "  name = " menu " >

< select name = " fwId "  size = " 5 "  multiple >
</ select >  
< input name = " item "  type = " button "  onClick = " addItems() "  value = " Ìí¼Ó " >  
< input name = " itemDel "  type = " button "  onClick = " delItems() "  value = " ɾ³ý "   >  
</ form >




新开窗口items.html:

< script language = " JavaScript " >
function  doSubmit(value,name) 
{
      
var  aa  =  window.opener.document;
    
var  myop  =  aa.createElement( " OPTION " );

    
for ( var  j  =   0 ; j  <  aa.menu.fwId.options.length; j ++
    {
          
if (value  ==  aa.menu.fwId.options[j].value)
            {
                alert(
" ÒѾ­±»Ñ¡Ôñ£¡ " );
                
return ;
            }
    }
    myop.text 
= name;
    myop.value 
= value;
    aa.menu.fwId.add(myop); 
}
</ script >

< form name = " items " >
    
< a onclick = " javascript:doSubmit('1','test1'); "  href = " # " > test1 </ a >< br >
    
< a onclick = " javascript:doSubmit('2','test2'); "  href = " # " > test2 </ a >< br >
</ form >

你可能感兴趣的:(职场,休闲)