HTML标签在showModalDialog中的应用

JavaScript的showModalDialog(模态对话框)中有提交按钮,在模态对话框中点击按钮会跳出新的页面,那么我们可以设置

<base target="_self">来解决该问题.

 <base target=_blank>//在空白页打开  
<base target=_parent>//用在框架中,在当前页的上一页(父亲)打开  
<base target=_search>//在浏览器搜索栏打开  
<base target=_self>//在当前页打开  
<base target=_top>//用在框架中,但是他的效果是清除框架来显示目标文档。这对于从框架结构转向无框架结构是很有作用的。


在IE7前的所有版本中,如果在showModalDialog中有个提交等按钮,可以直接在showModalDialog所打开的那个页面中的任何地方加入<base target="_self">就可以运行了,但是在IE7中必须把<base target="_self">放在<head></head>中的第一个位置。否则会点击提交按钮的时候会重新跳出一个新窗口。

这个属性有IE6与IE7之分。

注:

1、如果你是IE6,你将<base target="_self"/>加入到<head>标签里就可以了。

2、如果你是IE7,你必须将<base target="_self"/>加入到<head>的中间位置。

代码示例:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <base target="_self" />//关键点
    <title></title>
    <link href="../css/mains.css" rel="stylesheet" type="text/css" />

<script>   

    function OpenWin(ID) {
            window.showModalDialog('QRZJModalDialog.aspx?ID=' + ID.ClientID, '确认注记', 'dialogLeft=380px;dialogTop=180px;dialogWidth=450px;dialogHeight=100px;');//打开模式窗口
            location.reload();//点击确认刷新父窗口
            return false;
        }</script>
</head>
<body>
    <form id="form1" runat="server">
          <table width="100%" border="0" cellpadding="2" cellspacing="1" bgcolor="#c7bebc">
            <tr class="line-odd">
                <td align="center">
                    注记编号:<asp:TextBox ID="ZJBH" runat="server"></asp:TextBox>&nbsp;&nbsp;
                    <asp:Button ID="QUEREN" runat="server" Text="确认" OnClick="QUEREN_Click" />
                </td>
            </tr>
        </table>
    </form>
</body>
</html>

原文地址:https://www.cnblogs.com/ZhangGuiHai/p/2127019.html