博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

js ShowModalDialog向父窗口传参数

Posted on 2013-06-16 15:25  TimeFight  阅读(198)  评论(0)    收藏  举报

父窗口js代码

function openSelectReceiverUI(){
    myShowModalDialog("URL地址", 500, 500);
   }

 

表单

<s:hidden name="UserID" />
                        <s:textfield name="receiverName" cssClass=" required InputStyle" cssStyle="width:250px; float:left;" cssClass="required "/>
       <div onClick="openSelectReceiverUI()" class="FuncBtn" style="margin-left: 10px;">
        <div class="FuncBtnHead"></div>
        <div class="FuncBtnMemo">选择...</div>
        <div class="FuncBtnTail"></div>
       </div>

 

对超链接的美化

.FuncBtnHead {
 background: url(images/func_btn_head_bg.gif) no-repeat;
 float: left;
 width: 2px;
 height: 20px;
}

.FuncBtnMemo {
 background: url(images/func_btn_bg.gif) repeat-x;
 float: left;
 height: 20px;
 padding-top: 4px;
 padding-left: 8px;
 padding-right: 8px;
}

.FuncBtnTail {
 background: url(images/func_btn_tail_bg.gif) no-repeat;
 float: left;
 width: 2px;
 height: 20px;
}

 

子窗口

<script type="text/javascript">
  function selectMe( id, name ){
   var win = window.dialogArguments;
    win.document.forms[0].UserID.value = id;
   win.document.forms[0].receiverName.value = name;
   window.close();
  }

    </script>

<a href="javascript:selectMe('参数1', '参数2')">

 

 

 

最后  父窗口需要的js代码

function myShowModalDialog(url, width, height) {
    var arguments = window;

    if (!width) width = 350;
    if (!height) height = 350;
    var left = (screen.width - width) / 2;
    var top = (screen.height - height) / 2;
    var features = "" //
        // + "dialogLeft:" + left + ";"//           左边距
        // + "dialogTop:" + top + ";"//             上连距
            + "dialogWidth:" + width + "px;"//   宽度
            + "dialogHeight:" + height + "px;"// 高度
            + "center: yes;"//                    是否居中
            + "resizable: yes;"//                是否可以改变大小
            + "scroll: yes;"//                    当内容超过窗口大小时是否显示滚动条
            + "status: yes;"//                    是否显示状态栏

    window.showModalDialog(url, arguments, features);
}