从页面a弹出模态窗口b,从b按一个按钮返回给a一个值 同时关闭b 。用JS实现。
老板下达了任务,可是小弟对JS很不灵光,请哪位大哥帮帮我啊  先谢了:)

解决方案 »

  1.   

    //使用方法:建一个基页面,将下列函数复制过去,其它所有页面从基页面继承,在派生页面中按钮事件中就可以调用下面的函数
    //在弹出窗口的aspx中<head></head>间加入以下代码:<base target="_self">//弹出一个模式窗口
    //url:弹出窗体地址
    //width:弹出窗体宽度
    //height:弹出窗本高度
    //allowStatus:是否显示状态条
    //allowScroll:是否显示滚动条
    //refreshParent:返回时是否刷新父窗体
    //refreshButtonID:保留不用,即为空字符串 public void CspOpenWindowModal (string url, int width, int height,string allowStatus,string allowScroll,bool refreshParent,string refreshButtonID)
    {
    string options="'dialogWidth="+width+"px;dialogHeight ="+height+"px;"+
    "help=no;status="+allowStatus+";scroll="+allowScroll+"'";
    if(refreshParent==true)
    {
    GetPostDoPostBackScript();
    }
    RegisterStartupScript(Guid.NewGuid().ToString(), "<script language=\"JavaScript\">" + GetPopupScriptModal(url, options, refreshParent,refreshButtonID) + "</script>");
    } protected string GetPopupScriptModal(string url, string options,bool refreshParent,string refreshButtonID)
    {
    string returnScript;
    if(refreshParent==true)
    {
    returnScript="var w=window.showModalDialog(\"" + url + "\", '', " + options + ");__doPostBack('"+refreshButtonID+"','');";
    }
    else
    {
    returnScript="var w=window.showModalDialog(\"" + url + "\", '', " + options + ");";
    }
    return returnScript;
    }/************************************关闭窗体************************/
    //关闭一个窗口
    //refreshParent:是否刷新父窗体,对模式窗体无效,只能是false
    public void CspCloseWindow (bool refreshParent)
    {
    RegisterClientScriptBlock(Guid.NewGuid().ToString(), "<script language=\"JavaScript\">" + GetCloseWindowScript(refreshParent) + "</script>");
    } protected string GetCloseWindowScript(bool refreshParent)
    {
    string script="";
    if (refreshParent)
    {
    script = "window.opener.document.forms(0).submit();";
    }

    return script+"window.close();";
    }
      

  2.   

    1.父页面中的javascript代码function openwin(id,id2,id3)//打开新页面,传递相应的参数                                   {                                          window.open ('Showinfo.aspx?id=' + id+'&k='+id2+'&tablename='+id3, 'newwindow', 'height=400, width=280, top=200, left=200,toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');                                                      }                                   function openwin1(id,id2,id3)                                   {                                          window.open ('ShowinfoS.aspx?id=' + id+'&k='+id2+'&tablename='+id3, 'newwindow', 'height=400, width=280, top=200, left=200,toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');                                                      }            父页面中的htmlbutton<INPUT class="Button02" id="btnDutyDegInfo" style="WIDTH: 24px" onclick="openwin1('txtDutyDegInfo','txtDutyDegInfo1','dutydeglist');" type="button" value="..." name="Button1" runat="server">2.子页面中的javascript代码              function getUrlParam(url, param)//取得页面中的参数              {                     var re = new RegExp("(\\\?|&)" + param + "=([^&]*)(&|$)", "i");                     var m = url.match(re);                     if (m)                            return m[2];                     else                            return '';              }                            function go()              {                     var e = event.srcElement.parentElement.parentElement;                     var a = e.cells[0].innerText;                     var b = e.cells[1].innerText;                     var url = location.href.toLowerCase();                     var id = getUrlParam(url, 'id');//取得对应参数所传递过来的值                     var id2 =getUrlParam(url, 'k');                     if (id != '')                     {                                                      opener.document.getElementById(id).value = a;//将子页面中获得的值赋到父页面中                            opener.document.getElementById(id2).value = b;                            window.close();                     }                          }
     
    子页面中一个htmlbutton,添加onclick事件<input type="button" value="选择" Class="dgButton" onclick="go();"> 
      

  3.   

    zhilunchen(他山居士)高解!!!
    佩服!!!
    楼主结贴吧
      

  4.   

    楼主参考:
    farther.htm
    <form id ="form1" name ="form1" method ="post">传递过去的值:<input type="text" name="tt"><input type ="button" value ="传递" onclick ="doOpen()">
    返回来的值得:<input type="text" name="goBackValue" ></form>
    <script>
    function doOpen()
    {
    var ttValue = form1.tt.value;
    var getBackValue = showModalDialog("child.htm",ttValue,"");
    if (typeof(getBackValue)=="undefined") getBackValue = "";//当返回值出现以外的时候设置返回值为空(如用户没有点返回而是直接关闭了窗口)
    form1.goBackValue.value = getBackValue;//把返回的值给文本框goBackValue
    }
    </script>
    ------------------
    child.htm
    获得传递的值,修改该值后将改值返回:<input type="text" id="file_name">
    <input type ="button" id ="btnOk" value ="返回值" onclick ="goBack();">
    <script>
    var obj = dialogArguments;
    document.getElementById("file_name").value = obj;//获得传递的值function goBack()
    {
    var backValue = document.getElementById("file_name").value;
    window.returnValue = backValue;//设置返回值
    window.close();
    }
    </script>
    本地测试通过
    楼主根据需要可以修改的。
      

  5.   

    什么叫“模态窗口”?http://dev.csdn.net/article/27/27760.shtm
      

  6.   

    a页面js如下:
    function OrderEdit(iOrderID)
    {
      window.showModalDialog("B.asp?OrderType=0&OrderID=" + iOrderID, FrmCompanyPrOrder,"dialogHeight:580px; dialogWidth:800px; edge: raised; center: Yes; help: No; resizable: No; status: No; unadorned:Yes;");
    }
    B页面JS如下
    function SelectReturn()
    {
        var parFrm=window.dialogArguments;
        parFrm.TxtOtherIndustryListID.value="ID";
        parFrm.TxtOtherIndustryList.value="NAME";
        window.close();
    }
    其中,TxtOtherIndustryListID标识A页面必需有这样一个文本框