天-海-蓝-蓝 2023-02-18 07:58 采纳率: 53.8%
浏览 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 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测