showModalDialog模态窗口传值

一、即时传值,即在窗口中点击某项数据时把值传给父窗口

父窗口:p.html

<body>

<input type="txt" id="txtid"/> <a href="javascript:" οnclick="SelectUser()">选择</a>

</body>

<script>

function SelectUser()
        {
          URL="/admin/member/select_member.aspx";

/*-----------------------判断浏览器------------*/
          var userAgent = navigator.userAgent.toLowerCase();
            var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
            var is_moz = (navigator.product == 'Gecko') && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
            var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera) && userAgent.substr(userAgent.indexOf('msie') + 5, 3);
          loc_y=loc_x=200;//模态窗口定位
          if(is_ie)
          {
             loc_x=document.body.scrollLeft+event.clientX-100;
             loc_y=document.body.scrollTop+event.clientY+170;
          }
     //弹出模态窗口     window.showModalDialog(URL,self,"edge:raised;scroll:1;status:0;help:0;resizable:1;dialogWidth:"+400+"px;dialogHeight:"+350+"px;dialogTop:"+loc_y+"px;dialogLeft:"+loc_x+"px",true);
        }
        function clearuser()
        {
        document.getElementById("txtid").value="";
        }
    </script>

   子窗口页面:

<table class="TableList" width="100%" align="center">
        <tr class="TableData">
            <td class="lefttd">
                部门名称
            </td>
            <td style="text-align: left;" id="td1" οnclick="selectvalue()">
               开发部
            </td>
        </tr>
    </table>
    <script language="javascript" type="text/javascript">
    function selectvalue()
    {
    var pobj = window.dialogArguments;   //获得父窗口文本框对象
    pobj.document.all["txtid"].value+=document.getElementById("td1").innerHTML;
    }
    </script>

二、关闭窗口后传值

<body>

<input type="txt" id="txtid"/> <a href="javascript:" οnclick="SelectUser()">选择</a>

</body>

<script>

function SelectUser()
        {
          URL="/admin/member/select_member.aspx";

/*-----------------------判断浏览器------------*/
          var userAgent = navigator.userAgent.toLowerCase();
            var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
            var is_moz = (navigator.product == 'Gecko') && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
            var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera) && userAgent.substr(userAgent.indexOf('msie') + 5, 3);
          loc_y=loc_x=200;//模态窗口定位
          if(is_ie)
          {
             loc_x=document.body.scrollLeft+event.clientX-100;
             loc_y=document.body.scrollTop+event.clientY+170;
          }
     //弹出模态窗口    

var v="";

 v=window.showModalDialog(URL,self,"edge:raised;scroll:1;status:0;help:0;resizable:1;dialogWidth:"+400+"px;dialogHeight:"+350+"px;dialogTop:"+loc_y+"px;dialogLeft:"+loc_x+"px",true);
   document.getElementById("txtid").value=v;

}
        function clearuser()
        {
        document.getElementById("txtid").value="";
        }
    </script>

子窗口:

<table class="TableList" width="100%" align="center">
        <tr class="TableData">
            <td class="lefttd">
                部门名称
            </td>
            <td style="text-align: left;" id="td1" οnclick="selectvalue()">
               开发部
            </td>
        </tr>
    </table>
    <script language="javascript" type="text/javascript">
    function selectvalue()
    {
    window.retrunValue=document.getElementById("td1").innerHTML;
    }
    </script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值