【转】用JS实现弹出模式对话框,实现页面传值

功能介绍:a.aspx 点击“添加”,弹出b.aspx模式对话框,在b页面里的TextBox1填写玩内容后,点击确定,b页面关闭,a页面的TextBox1显示b页面刚填写的内容.

A页面代码:

<html >
<head runat="server">
    <title></title>
        <script language="javascript">
function opendialog()
{
   var someValue=window.showModalDialog ("b.aspx","","dialogWidth=300px;dialogHeight=250px;status=no;help=no;scrollbars=no")
   document.form1.TextBox1.value=someValue;
}
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <input id="Button1" type="button" value="button" onclick="opendialog()" /></div>
    </form>
</body>
</html>

B页面代码:

<html>
<head runat="server">
    <title></title>

    <script language="javascript">

        function a()
        {
            //读取TexBox1的内容,返回给调用页面
            parent.window.returnValue = document.getElementById("TextBox1").value;
            window.close();
        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <input id="Button1" type="button" value="button" onclick="a()" /></div>
    </form>
</body>
</html>


      

                

注意:因为只调用客户端脚本,所以这里的button用的都是Html的button而不是ASP.NET的Button,这样不用刷新页面,效率更高,若用Asp.net的Button,则是用OnClientClick()调用JS方法,Asp.net的Button的OnClick()是调用服务器上的方法的。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值