Menu.Target 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定目標視窗或框架,用以顯示與選單項目相關的網頁內容。
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
屬性值
顯示連結網頁內容的目標視窗或框架。 預設值為空字串(“”),用於聚焦刷新視窗或框架。
範例
以下程式碼範例示範如何使用該 Target 屬性指定,當使用者點擊每個選單項目時,該選單項目所連結的內容應顯示在新視窗中。
<%@ 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 屬性指定在點擊選單項目時,顯示與該選單項目連結的網頁內容的視窗或框架。 值必須以 A 到 Z 範圍內的字母開頭(不區分大小寫),除非某些特殊值以底線開頭,如下表所示。
| 目標值 | 說明 |
|---|---|
_blank |
它會在一個沒有框架的新視窗中渲染內容。 |
_parent |
將內容渲染到直接的框架集父節點。 |
_search |
在搜尋窗格中呈現內容。 |
_self |
能在畫面中聚焦渲染內容。 |
_top |
能在完整視窗中渲染內容,且不包含框架。 |
備註
請查看瀏覽器文件,確認該 _search 數值是否被支援。 例如,Internet Explorer 5.0 及以上版本支援目標 _search 值
此屬性適用於控制項中 Menu 的所有選單項目。 你可以選擇性地覆蓋這個屬性,方法是直接設定 Target 每個 MenuItem 物件的屬性。
備註
該 Target 屬性會以目標屬性的形式呈現。 在 XHTML 1.1 嚴格文件類型定義中,不允許在錨點元素上設定目標屬性。 如果渲染輸出必須符合 XHTML 或無障礙標準,則不要設定該 Target 屬性。 欲了解更多資訊,請參閱 Visual Studio 中的 XHTML 標準及Visual Studio 與 ASP.NET 中的 ASP.NET 與無障礙。