Menu.Target 属性

定义

获取或设置用来显示菜单项的关联网页内容的目标窗口或框架。Gets or sets the target window or frame in which to display the Web page content associated with a menu item.

public:
 property System::String ^ Target { System::String ^ get(); void set(System::String ^ value); };
public string Target { get; set; }
member this.Target : string with get, set
Public Property Target As String

属性值

String

显示所链接的网页内容的目标窗口或框架。The target window or frame in which to display the linked Web page content. 默认值为空字符串 (""),该值刷新具有焦点的窗口或框架。The default value is an empty string (""), which refreshes the window or frame with focus.

示例

下面的代码示例演示如何使用 Target 属性来指定在用户单击菜单项时,链接到每个菜单项的内容应显示在新窗口中。The following code example demonstrates how to use the Target property to specify that the content linked to each menu item should be displayed in a new window when the user clicks that menu item.


<%@ Page Language="C#" %>

<!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">
    <title>Menu Target Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>Menu Target Example</h3>
    
      <asp:menu id="NavigationMenu"
        staticdisplaylevels="2"
        staticsubmenuindent="10" 
        orientation="Vertical"
        target="_blank"  
        runat="server">

        <items>
          <asp:menuitem navigateurl="Home.aspx" 
            text="Home"
            tooltip="Home">
            <asp:menuitem navigateurl="Music.aspx"
              text="Music"
              tooltip="Music">
              <asp:menuitem navigateurl="Classical.aspx" 
                text="Classical"
                tooltip="Classical"/>
              <asp:menuitem navigateurl="Rock.aspx"
                text="Rock"
                tooltip="Rock"/>
              <asp:menuitem navigateurl="Jazz.aspx"
                text="Jazz"
                tooltip="Jazz"/>
            </asp:menuitem>
            <asp:menuitem navigateurl="Movies.aspx"
              text="Movies"
              tooltip="Movies">
              <asp:menuitem navigateurl="Action.aspx"
                text="Action"
                tooltip="Action"/>
              <asp:menuitem navigateurl="Drama.aspx"
                text="Drama"
                tooltip="Drama"/>
              <asp:menuitem navigateurl="Musical.aspx"
                text="Musical"
                tooltip="Musical"/>
            </asp:menuitem>
          </asp:menuitem>
        </items>
      
      </asp:menu>

    </form>
  </body>
</html>


<%@ Page Language="VB" %>

<!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">
    <title>Menu Target Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>Menu Target Example</h3>
    
      <asp:menu id="NavigationMenu"
        staticdisplaylevels="2"
        staticsubmenuindent="10" 
        orientation="Vertical"
        target="_blank"  
        runat="server">

        <items>
          <asp:menuitem navigateurl="Home.aspx" 
            text="Home"
            tooltip="Home">
            <asp:menuitem navigateurl="Music.aspx"
              text="Music"
              tooltip="Music">
              <asp:menuitem navigateurl="Classical.aspx" 
                text="Classical"
                tooltip="Classical"/>
              <asp:menuitem navigateurl="Rock.aspx"
                text="Rock"
                tooltip="Rock"/>
              <asp:menuitem navigateurl="Jazz.aspx"
                text="Jazz"
                tooltip="Jazz"/>
            </asp:menuitem>
            <asp:menuitem navigateurl="Movies.aspx"
              text="Movies"
              tooltip="Movies">
              <asp:menuitem navigateurl="Action.aspx"
                text="Action"
                tooltip="Action"/>
              <asp:menuitem navigateurl="Drama.aspx"
                text="Drama"
                tooltip="Drama"/>
              <asp:menuitem navigateurl="Musical.aspx"
                text="Musical"
                tooltip="Musical"/>
            </asp:menuitem>
          </asp:menuitem>
        </items>
      
      </asp:menu>

    </form>
  </body>
</html>

注解

使用 " Target 属性" 指定在单击菜单项时要在其中显示其链接到菜单项的 Web 内容的窗口或框架。Use the Target property to specify the window or frame in which to display the Web content linked to a menu item when that menu item is clicked. 值必须以 A 到 Z 范围内的字母(不区分大小写)打头,但某些以下划线打头的特殊值除外,如下表所示:Values must begin with a letter in the range of A through Z (case-insensitive), except for certain special values that begin with an underscore, as shown in the following table.

目标值Target value 说明Description
_blank 将内容呈现在一个没有框架的新窗口中。Renders the content in a new window without frames.
_parent 将内容呈现在上一个框架集父级中。Renders the content in the immediate frameset parent.
_search 在搜索窗格中呈现内容。Renders the content in the search pane.
_self 将内容呈现在含焦点的框架中。Renders the content in the frame with focus.
_top 将内容呈现在没有框架的全窗口中。Renders the content in the full window without frames.

备注

请查看浏览器文档,确定是否支持 _search 值。Check your browser documentation to determine if the _search value is supported. 例如,Internet Explorer 版本5.0 及更高版本支持 _search 目标值For example, Internet Explorer versions 5.0 and above support the _search target value

此属性适用于控件中的所有菜单项 MenuThis property applies to all menu items in a Menu control. 可以通过 Target 直接设置每个对象的属性来有选择地重写此属性 MenuItemYou can selectively override this property by setting the Target property of each MenuItem object directly.

备注

Target属性呈现为目标特性。The Target property renders as a target attribute. 不允许在 XHTML 1.1 strict 文档类型定义中使用定位点元素的目标属性。The target attribute on anchor elements is not allowed in the XHTML 1.1 strict document type definition. 如果呈现的输出必须符合 XHTML 或可访问性标准,请不要设置 Target 属性。If rendered output must conform to XHTML or accessibility standards, do not set the Target property. 有关详细信息,请参阅Visual studio 中的 XHTML 标准和 visual studio 和 ASP.NET 中的 ASP.NET 和可访问性For more information, see XHTML Standards in Visual Studio and ASP.NET and Accessibility in Visual Studio and ASP.NET.

适用于

另请参阅