天-海-蓝-蓝 2023-02-18 07:58 采纳率: 50%
浏览 61
已结题

关于window.open打开子页面的问题


<table align="center" cellpadding="4" cellspacing="1" class="toptable grid" border="1">
      <form name="form1" method="post">
        <tr>      
        <td height="30" align="right">购买客户:</td>
        <td class="category"><input name="huiyuan" readonly onClick="JavaScript:window.open('1.HTML?form=form1&field=huiyuan&field2=id_huiyuan&field3=zu','','directorys=no,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=1700,height=800,top=176,left=180');" style="width:150px" value="单击选择客户">
          <input type="hidden" name="id_huiyuan" id="id" />
          <input type="text" name="zu" style="width:120px" readonly>
         </td>                
      </tr>
       <tr>
        <td align="right" height="30">收货地址:</td>
        <td class="category"><input name="address" type="text" id="address" size="100" maxlength="200"> <font color="#ff0000">*</font>
        <div id="address2"></div>
        </td>
        </tr>
    
      </form>
</table>

<meta   http-equiv="Content-Type"   content="text/html; charset=utf-8"/>

<table align="center" cellpadding="4" cellspacing="1" class="toptable grid" border="1">
  <tr 
  onMouseOver="this.className='highlight'" 
  onMouseOut="this.className=''" 
  onDblClick="
  window.opener.document.form1.huiyuan.value='二公司';
  window.opener.document.form1.id_huiyuan.value='340757';
  window.opener.document.form1.zu.value='负责业务员:李';
   window.opener.document.all.address2.innerHTML='二公司地址1
二公司地址2
二公司地址3' window.close();"
>
<td height="25" align="center">第二个公司</td> <td align="center">含税</td> <td align="center">余总</td> </tr> <tr onMouseOver="this.className='highlight'" onMouseOut="this.className=''" onDblClick=" window.opener.document.form1.huiyuan.value='三公司'; window.opener.document.form1.id_huiyuan.value='340754'; window.opener.document.form1.zu.value='负责业务员:王'; window.opener.document.all.address2.innerHTML='三公司地址1
三公司地址2
三公司地址3' window.close();"
>
<td height="25" align="center">第三个公司</td> <td align="center">未税</td> <td align="center">梁总</td> </tr> </table>

一个是主页面,一个是子页面,我需要在点击选择客户后,出现三个地址,当点击某一个地址时,该地址自动填入“address”文字框

img

  • 写回答

10条回答 默认 最新

  • Hello World, 2023-02-18 09:22
    关注
    主页面代码:
    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
        <form name="form1" method="post">
            <table align="center" cellpadding="4" cellspacing="1" class="toptable grid" border="1">
                <tr>
                    <td height="30" align="right">购买客户:</td>
                    <td class="category">
                        <input name="huiyuan" id="huiyuan" readonly onClick="OpenCustomerDialog();" style="width:150px" value="单击选择客户">
                        <input type="hidden" name="id_huiyuan" id="id" />
                        <input type="text" name="zu" id="zu" style="width:120px" readonly>
                    </td>
                </tr>
                <tr>
                    <td align="right" height="30">收货地址:</td>
                    <td class="category">
                        <input name="address" type="text" id="address" size="100" maxlength="200"> <font color="#ff0000">*</font>
                        <div id="address2"></div>
                    </td>
                </tr>
            </table>
        </form>
    </body>
    </html>
    <script>
        function OpenCustomerDialog() {
            var dialog = window.open('1.HTML?form=form1&field=huiyuan&field2=id_huiyuan&field3=zu', '', 'directorys=no,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=1700,height=800,top=176,left=180');
            console.log(dialog);
        }
        function SetCustomer(customer) {
            console.log(customer);
            document.getElementById('huiyuan').value = customer.name;
            document.getElementById('id').value = customer.id;
            document.getElementById('zu').value = customer.zu;
            var addObj = document.getElementById('address2');
            var address = customer.address.split('\n');
            var addressHTML = '';
            for (var i = 0, n = address.length; i < n; i++) {
                addressHTML += '<div onclick="document.getElementById(\'address\').value=\'' + address[i] + '\'";>' + address[i] + '</div>';
            }
            document.getElementById('address2').innerHTML = addressHTML;
        }
    </script>
    

    子页面代码:

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
        <table align="center" cellpadding="4" cellspacing="1" class="toptable grid" border="1">
            <tr onMouseOver="this.className='highlight'"
                onMouseOut="this.className=''"
                onDblClick="SetCustomer({name:'二公司',id:'340757',zu:'负责业务员:李',address:'二公司地址1\n二公司地址2\n二公司地址3'});">
                <td height="25" align="center">第二个公司</td>
                <td align="center">含税</td>
                <td align="center">余总</td>
            </tr>
    
            <tr onMouseOver="this.className='highlight'"
                onMouseOut="this.className=''"
                onDblClick="SetCustomer({name:'三公司',id:'340754',zu:'负责业务员:王',address:'三公司地址1\n三公司地址2\n三公司地址3'});">
                <td height="25" align="center">第三个公司</td>
                <td align="center">未税</td>
                <td align="center">梁总</td>
            </tr>
    
        </table>
    </body>
    </html>
    <script>
        function SetCustomer(customer) {
            window.opener.SetCustomer(customer);
            window.close();
        }
    </script>
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(9条)

报告相同问题?

问题事件

  • 系统已结题 2月27日
  • 已采纳回答 2月19日
  • 创建了问题 2月18日

悬赏问题

  • ¥15 streamingtool
  • ¥15 MATLAB图像问题
  • ¥20 树莓派5做人脸情感识别与反馈系统
  • ¥15 selenium 控制 chrome-for-testing 在 Linux 环境下报错 SessionNotCreatedException
  • ¥15 使用pyodbc操作SQL数据库
  • ¥15 MATLAB实现下列
  • ¥30 mininet可视化打不开.mn文件
  • ¥50 C# 全屏打开Edge浏览器
  • ¥80 WEBPACK性能优化
  • ¥30 python拟合回归分析