JavaScript는 하위 창을 팝업하고 상위 창에 값을 전달합니다.

새 상위 창 페이지:
다음 스크립트 추가

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>First</title>
</head>
<script type="text/javascript">
function ShowDialog(Url)
{
      var  iWidth=560; //
      var  iHeight=300;//
      var  iTop=(window.screen.height-iHeight-100)/2;
      var  iLeft=(window.screen.width-iWidth)/2;
      var returnValue=window.showModalDialog(Url, "newwindow", "dialogHeight:"+iHeight+"px; dialogWidth:"+iWidth+"px; toolbar:no; menubar:no; scrollbars:no; resizable:no; location:no; status:no;left:200px;top:100px;");
      document.getElementById("TextBox1").innerText=returnValue;
}
</script>
<body>
    <form id="form1" runat="server">
         <input id="Button1" type="button" value="button" onclick="ShowDialog('./second.aspx')" />
         <div><asp:TextBox ID="TextBox1" runat="server" Width="67px"></asp:TextBox></div>
     </form>
</body>
</html>
second를 만듭니다.html 페이지:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>second</title>
    <!--<base target="_self" ></base>-->
</head>
<script language="javascript">
    function closeDiag()
    {
        window.opener=null;
        window.close();
    } 
    function OK()
    {
        var Value=document.getElementsByName("myRadio");
        for(var i=0;i<Value.length;i++)
        {
            if(Value[i].checked)
            { 
                window.returnValue = Value[i].value;
                window.close();
            }
            else
            {
                document.getElementById("Lab_Info").innerText=" , !";
            }
        }     
    } 
</script>
<body>
    <form id="form1" runat="server">
    <div>
          <asp:DataGrid ID="dgSjygl" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                        BackColor="White" Font-Size="9pt" PageSize="5" Width="100%" Height="127px" OnItemDataBound="dgSjygl_ItemDataBound">
                        <PagerStyle Mode="NumericPages" />
                        <AlternatingItemStyle BackColor="Gainsboro" />
                        <ItemStyle BackColor="#EEEEEE" ForeColor="Black" HorizontalAlign="Center" />
                        <Columns>
                            <asp:TemplateColumn>            
                                <HeaderTemplate>
                                    <label> </label>
                                </HeaderTemplate>
                                <ItemTemplate>                                   
                                    <input type="radio" id="myRadio" name="myRadio"  value='<%# DataBinder.Eval(Container.DataItem, "id") %>'>
                                </ItemTemplate>
                                <HeaderStyle Font-Bold="True" HorizontalAlign="Center" Width="60px" />
                                <ItemStyle HorizontalAlign="Center" />
                            </asp:TemplateColumn>
                            <asp:BoundColumn DataField="ID" HeaderText=" ">
                                <HeaderStyle Font-Bold="True"  Width="75px" HorizontalAlign="Center"/>
                            </asp:BoundColumn>
                            <asp:BoundColumn DataField="MC" HeaderText=" ">
                                <HeaderStyle Font-Bold="True"  Width="90px" HorizontalAlign="Center"/>
                                <ItemStyle HorizontalAlign="Center" />
                            </asp:BoundColumn>
                            <asp:BoundColumn DataField="BT" HeaderText=" ">
                                <HeaderStyle Font-Bold="True" HorizontalAlign="Center"/>
                            </asp:BoundColumn>
                        </Columns>
                        <HeaderStyle BackColor="#7481BA" ForeColor="Yellow" Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" Font-Size="Small" />
                    </asp:DataGrid>
    </div>
    <div>
          <input id="Btn_OK" type="button" onclick="OK()" value=" "/>
          <input id="Btn_Cancel" type="button" onclick="clickDiag()"  value=" " />
     </div>       
    </form>
</body>
</html>
이상은 본인이 이 간단한 기능을 실현한 모든 내용입니다. 더 편리한 방법이 있을 것 같습니다. 아는 파트너가 있으면 댓글로 설명해 주세요.

좋은 웹페이지 즐겨찾기