fu.htm代码: <a href="#" onclick="window.open('zi1.htm','','status=yes,width=200,height=200')"> 子窗口1 </a> <br /> <br /> 
<a href="#" onclick="window.open('zi2.htm','','status=yes,width=200,height=200')"> 子窗口1 </a> <br /> <br /> 
<a href="#" onclick="window.open('zi3.htm','','status=yes,width=200,height=200')"> 子窗口1 </a> <br /> <br /> 
<input name="he" type="text" readonly="true"> he <br /> zi1.htm代码: <input name="zi1" type="text" readonly="true"> zi1 <br /> 
<br /> 
<input type="button" value="关闭窗口" onclick="javascript:window.close();">
zi2.htm代码: <input name="zi2" type="text" readonly="true"> zi2 <br /> 
<br /> 
<input type="button" value="关闭窗口" onclick="javascript:window.close();">
zi3.htm代码: <input name="zi3" type="text" readonly="true"> zi3 <br /> 
<br /> 
<input type="button" value="关闭窗口" onclick="javascript:window.close();">子窗口是动态生成的,就是不一定只有三个(能解决3个子窗口的也可以!)。 
要求的计算是:在zi1中输入一个数a(如:2),关闭zi1窗口,则父窗口中显示a(如:2),如果再打开zi2输入b(如:3),关闭zi2窗口,则父窗口中显示a+b(如:5),如果再打开zi3输入c(如:4),关闭zi3窗口,则父窗口中显示a+b+c(如:9),子窗口中的值可以修改,修改不累加。 高手帮一下啊!拜托!!

解决方案 »

  1.   

    i1.htm代码:  
    <input name="zi1" type="text">  zi1  <br />   
    <br />  
    <input type="button" value="关闭窗口" onclick="xs();">  
    <script>
    function xs(){
    window.opener.document.getElementById("he").value=parseInt(window.opener.document.getElementById("he").value)+parseInt(document.getElementById("zi1").value)
    window.close();
    }
    </script>i2.htm代码:
    <input name="zi2" type="text">  zi2 <br />   
    <br />  
    <input type="button" value="关闭窗口" onclick="xs();">  
    <script>
    function xs(){
    window.opener.document.getElementById("he").value=parseInt(window.opener.document.getElementById("he").value)+parseInt(document.getElementById("zi2").value)
    window.close();
    }
    </script>i3.htm代码:
    <input name="zi3" type="text">  zi3 <br />   
    <br />  
    <input type="button" value="关闭窗口" onclick="xs();">  
    <script>
    function xs(){
    window.opener.document.getElementById("he").value=parseInt(window.opener.document.getElementById("he").value)+parseInt(document.getElementById("zi3").value)
    window.close();
    }
    </script>
      

  2.   

    父窗口:
    <script>
    function add(n){
        var result = document.all["he"];
        result.value=(result.value==""?0:parseInt(result.value))+parseInt(n);
    }
    </script>
    <a href="#" onclick="window.open('zi1.htm','','status=yes,width=200,height=200')"> 子窗口1 </a> <br /> <br /> 
    <a href="#" onclick="window.open('zi2.htm','','status=yes,width=200,height=200')"> 子窗口1 </a> <br /> <br /> 
    <a href="#" onclick="window.open('zi3.htm','','status=yes,width=200,height=200')"> 子窗口1 </a> <br /> <br /> 
    <input name="he" type="text" readonly="true"> he <br /> 
    子窗口:<input name="zi1" type="text"  />
    <br />   
    <br />   
    <input type="button" value="关闭窗口" onclick="window.opener.add(document.all["zi1"].value);window.close();" /> 
      

  3.   

    改下引号
    <input name="zi1" type="text"  />
    <br />   
    <br />   
    <input type="button" value="关闭窗口" onclick="window.opener.add(document.all['zi1'].value);window.close();" /> 
      

  4.   

    a.htm
     <script type="text/javascript">
    function ss(){
    document.all.t1.value=document.all.t1.value*document.all.t2.value;
    }
    </script><input name=t1   size=20>   
    <input name=t2   size=20 type="hidden"> 
    <input   type=button   value=show   onclick="document.all.t2.value=document.all.t1.value; window.open('b.htm','zyc','toolbar=no,scrollbars=yes,resizable=no,top=200,left=300,width=400,height=180');">   
    <input   type=button   value="两次乘"  onclick="ss()"> b.htm
    <br/><br/><br/>
    <input name="w">*<input name="q"><input type="button" value="求积"onclick="opener.document.all.t1.value=document.all.w.value*document.all.q.value; window.close();">
      

  5.   

    很简单,就是window.opener的使用
      

  6.   

    以上的好像都不对啊,子窗口的值都不能修改啊,修改就累加上去了,我要的是修改子窗口的值不累加啊。
    比如:第一次打开zi1填入值1,关闭,这时父窗口的值应该是1,但是我再打开zi1,输入值2,关闭,父窗口的值就变成1+2=3了,我要的是父窗口的值还是2啊;如果是只有一个子窗口的话不难,关键是有多个子窗口,要求的是每个子窗口值的和。郁闷!高手来吧!!!
      

  7.   

    很简单  用一个住页面的数组来纪录子的值父窗口<script>
    var zi = [];
    function add(n, o){
        var result = document.all["he"];
    if(zi[o] != n){  //子窗口值改变
    result.value=(result.value==""?0:parseInt(result.value))+parseInt(n);
    zi[o] = n;
    }
    }
    </script>
    <a href="#" onclick="window.open('z1.html','','status=yes,width=200,height=200')"> 子窗口1 </a> <br /> <br /> 
    <a href="#" onclick="window.open('z2.html','','status=yes,width=200,height=200')"> 子窗口2 </a> <br /> <br /> 
    <a href="#" onclick="window.open('z3.html','','status=yes,width=200,height=200')"> 子窗口3 </a> <br /> <br /> 
    <input name="he" type="text" readonly="true"> he <br /> 
    子窗口<input name="zi1" type="text"  />
    <br />   
    <br />   <!-- 不同子页面函数第二个参数设置为不同 -->
    <input type="button" value="关闭窗口" onclick="window.opener.add(document.all['zi1'].value, 1 );window.close();" /> 
      

  8.   

    一定要要用子窗口么?貌似现在很流行的是ajax吧,
    用lightbox(or thickbox)~
      

  9.   

    lsc1202001 还是一样,修改子窗口的值的话父窗口会累加!怎么用呢?高手可以详细一点么?
      

  10.   

    自己搜索下,带演示的 lightbox(or thickbox),看效果就知道了~
      

  11.   

    哦 知道你的意思了  改下var zi = [];
    function add(n, o){
        var result = document.all["he"];
        if(zi[o] == null){  //子窗口值改变
            result.value=(result.value==""?0:parseInt(result.value))+parseInt(n);
           zi[o] = n;
        }
    }
    </script>
    <a href="#" onclick="window.open('z1.html','','status=yes,width=200,height=200')"> 子窗口1 </a> <br /> <br /> 
    <a href="#" onclick="window.open('z2.html','','status=yes,width=200,height=200')"> 子窗口2 </a> <br /> <br /> 
    <a href="#" onclick="window.open('z3.html','','status=yes,width=200,height=200')"> 子窗口3 </a> <br /> <br /> 
    <input name="he" type="text" readonly="true"> he <br /> 
      

  12.   

    无语 
    子窗口是这样的么?<input name="zi1" type="text"  />
    <br />   
    <br />   <!-- 不同子页面函数第二个参数设置为不同 -->
    <input type="button" value="关闭窗口" onclick="window.opener.add(document.all['zi1'].value, 1 );window.close();" /> <input name="zi2" type="text"  />
    <br />   
    <br />   <!-- 不同子页面函数第二个参数设置为不同 -->
    <input type="button" value="关闭窗口" onclick="window.opener.add(document.all['zi2'].value, 2 );window.close();" /> <input name="zi3" type="text"  />
    <br />   
    <br />   <!-- 不同子页面函数第二个参数设置为不同 -->
    <input type="button" value="关闭窗口" onclick="window.opener.add(document.all['zi3'].value, 3 );window.close();" /> 
      

  13.   

    楼主的意思是不是这样:test.htm
    <script>
    function add(n){
        var result = document.all["he1"];
        result.value=(result.value==""?0:parseInt(result.value))+parseInt(n);
    }
    </script>
    <a href="#" onclick="window.open('t1.htm','','status=yes,width=200,height=200')"> 子窗口1 </a> <br /> <br /> 
    <a href="#" onclick="window.open('t2.htm','','status=yes,width=200,height=200')"> 子窗口1 </a> <br /> <br /> 
    <a href="#" onclick="window.open('t3.htm','','status=yes,width=200,height=200')"> 子窗口1 </a> <br /> <br /> 
    <input name="he1" type="text" readonly="true"> he1 <br /> 
    t1.htm
    <input name="zi1" type="text"  onblur="add()"/>
    <input name="m" type="text"  value="" type="hidden"/>
    <br />   
    <br />   <script language="javascript">
    function add(){
    if(document.all['m'].value==""){
    document.all['m'].value=window.opener.document.all['he1'].value;
    }
    if(document.all['m'].value!=""){
    window.opener.document.all['he1'].value=document.all['m'].value;
    window.opener.add(document.all['zi1'].value);
    }
    else{
    window.opener.add(document.all['zi1'].value);
    document.all['m'].value=window.opener.document.all['he1'].value;
    }
    }
    </script>
      

  14.   

    是这样啊<script>
    var zi = [];
    function add(n, o){
        var result = document.all["he"];
        var number = parseInt(n);
        if(zi[o] != n){  //子窗口值改变
            result.value=(result.value==""?0:parseInt(result.value)) -zi[o] + n;
            zi[o] = n;
        }
    }
    </script>
    <a href="#" onclick="window.open('z1.html','','status=yes,width=200,height=200')"> 子窗口1 </a> <br /> <br /> 
    <a href="#" onclick="window.open('z2.html','','status=yes,width=200,height=200')"> 子窗口2 </a> <br /> <br /> 
    <a href="#" onclick="window.open('z3.html','','status=yes,width=200,height=200')"> 子窗口3 </a> <br /> <br /> 
    <input name="he" type="text" readonly="true"> he <br /> 
      

  15.   

    晕 改下<script>
    var zi = [0,0,0,0];
    function add(n, o){
        var result = document.all["he"];
        var number = parseInt(n);
        if(zi[o] != number){  //子窗口值改变
            result.value=(result.value==""?0:parseInt(result.value)) -zi[o] + number;
            zi[o] = number;
        }
    }
    </script>
    <a href="#" onclick="window.open('z1.html','','status=yes,width=200,height=200')"> 子窗口1 </a> <br /> <br /> 
    <a href="#" onclick="window.open('z2.html','','status=yes,width=200,height=200')"> 子窗口2 </a> <br /> <br /> 
    <a href="#" onclick="window.open('z3.html','','status=yes,width=200,height=200')"> 子窗口3 </a> <br /> <br /> 
    <input name="he" type="text" readonly="true"> he <br /> 
      

  16.   

    以上的好像都不对啊,子窗口的值都不能修改啊,修改就累加上去了,我要的是修改子窗口的值不累加啊。 
    比如:第一次打开zi1填入值1,关闭,这时父窗口的值应该是1,但是我再打开zi1,输入值2,关闭,父窗口的值就变成1+2=3了,我要的是父窗口的值还是2啊;如果是只有一个子窗口的话不难,关键是有多个子窗口,要求的是每个子窗口值的和。郁闷!高手来吧!!!我给你的就是可以用的!我测试验证才发的例子
      

  17.   

    这破问题还没解决啊。修改了一下,应该是楼主的意思
    t1.htm
    <input name="zi1" type="text"  onblur="add()"/>
    <input name="m" type="text"  value="" type="hidden" />
    <input name="m2" type="text"  value="" type="hidden" />
    <br />   
    <br />   <script language="javascript">
    document.all['m'].value=window.opener.document.all['he1'].value;
    if(document.all['m'].value==''){
    document.all['m2'].value=true;    //表示第一次输入
    }
    else{
    document.all['m2'].value=false;
    }function add(){
    if(document.all['m2'].value=='true'){
            window.opener.document.all['he1'].value=document.all['zi1'].value;
    }
    else{
       window.opener.document.all['he1'].value=parseInt(document.all['zi1'].value)+parseInt(document.all['m'].value);
    }
    }
    </script>
      

  18.   

    还是差一点点!!高手就是高手啊!!!就是同一个子窗口关闭后再打开修改还是会累加啊!!我要的是同一个子窗口修改值不累加,关闭后再打开修改还是不累加(比如我打开zi1,输入1后关闭,父窗口值为1,再打开zi2输入2,关闭,父窗口值为3,这时候我再打开zi1,输入3,父窗口的值应该是zi2+zi1=5,而不是原父窗口的值3+zi1=6啊),简单说就是父窗口的值始终等于各子窗口的值之和,只不过子窗口的值可以修改!!汗啊!!不知我这回说的够明白了没有啊?拜托高手来吧!!
      

  19.   

    <script>
    var   aa=[0,0,0]function znum(n,i){
        var result = document.getElementById("he");
        var number = parseInt(n);
        if(aa[i] != number){  //子窗口值改变
    if(result.value==""){
    result.value=number;
    }
    else{
    result.value=parseInt(result.value)-parseInt(aa[i]) + number;
    }
            aa[i] = number;
        }
    }
    </script>
    <a href="#" onclick="window.open('zi1.htm','','status=yes,width=200,height=200')">  子窗口1  </a>   <br />   <br />   
    <a href="#" onclick="window.open('zi2.htm','','status=yes,width=200,height=200')">  子窗口1  </a>   <br />   <br />   
    <a href="#" onclick="window.open('zi3.htm','','status=yes,width=200,height=200')">  子窗口1  </a>   <br />   <br />   
    <input name="he" type="text" readonly="true">  he  <br />  
    zi1.htm
    <input name="zi1" type="text">   zi1   <br />     
    <br />    
    <input type="button" value="关闭窗口" onclick="xs();">    
    <script language="javascript">
    function xs(){
            window.opener.znum(document.getElementById("zi1").value,0);
    window.close(); 
    }
    </script>zi2.htm<input name="zi2" type="text">   zi2   <br />     
    <br />    
    <input type="button" value="关闭窗口" onclick="xs();">    
    <script language="javascript">
    function xs(){
            window.opener.znum(document.getElementById("zi2").value,1);
    window.close(); 
    }
    </script>
      

  20.   

    漏了zi3.htm的代码<input name="zi3" type="text">   zi3   <br />     
    <br />    
    <input type="button" value="关闭窗口" onclick="xs();">    
    <script language="javascript">
    function xs(){
            window.opener.znum(document.getElementById("zi3").value,2);
    window.close(); 
    }
    </script>
      

  21.   

    其实很简单的,被楼主给忽悠复杂了父窗口三个隐藏text,分别放3个子窗口的值。子窗口关闭时将相应的值放入父窗口的相应text里,然后对父窗口的三个text进行求和,结果放入he里和32楼用数组一样的道理
      

  22.   


    想再问一下,如果我想把“<script language="javascript">
    function xs(){
            window.opener.znum(document.getElementById("zi1").value,0);
    window.close(); 
    }
    </script>”中的“value,0”中的数字“0”换成别的比如这样“342hj-dsh3w-djw3e-df212”的可以吧?该怎么改呢??还有就是计算有时候会出错,比如和会是“NaN”??
      

  23.   

    大哥,你求和,还要加上字母和符号你能求和吗?
    比如和会是“NaN”
    这个是因为没做判断完啊
    对一些非法赋值没过滤
    342hj-dsh3w-djw3e-df212
    你这个是一个序列号形式怎么可能求和啊?
      

  24.   

    window.opener.znum(document.getElementById("zi1").value,0);
    你是说后面的那个0?
    这个肯定不行的,这个0代表的是数组
    <script> 
    var   aa=[0,0,0] function znum(n,i){ 
        var result = document.getElementById("he"); 
        var number = parseInt(n); 
        if(aa[i] != number){  //子窗口值改变 
        if(result.value==""){ 
        result.value=number; 
        } 
        else{ 
        result.value=parseInt(result.value)-parseInt(aa[i]) + number; 
        } 
            aa[i] = number; 
        } 

    </script> 仔细看这部分参数i是作为数组里用的,如果你不是数字形式那肯定会出错啊!
      

  25.   


    因为是动态生成的啊,只有这么一个参数(不好确定一共有几个子窗口,只有这个参数是相异的),可以提取这一串“342hj-dsh3w-djw3e-df212”中的数字吗?具体怎么做呢?怎么我提取出来做的都不行(在一个页面上可以提取出来!)!郁闷……啊……
      

  26.   

    这一串“342hj-dsh3w-djw3e-df212”不是43楼说的序列号,其实就是input的id,也是动态生成的!
      

  27.   

    ID与他无关啊
    动态生成与他没关系
    你的 ID为什么要用这个来做呢???
    换一些方便的不好?
    比如a0
    a1这样的话你取出来也方便
    也容易得到当前有几个窗口
    而且也有也正好符合数组下标的要求
      

  28.   


    晕了!ID早就定了的啦,这时要改?!唉……我只是想,如果可以把他的数字提取出来,放到“0”那个位置不就ok啦!现在问题是,单独的话可以把数字提取出来,放到“window.opener.znum(document.getElementById("zi1").value,0); ”这里面的话就不行了,怎么办呢??