HtmlElement.InnerText 屬性

定義

取得或設定指派給此項目的文字。

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

屬性值

String

此項目的文字,未存在任何 HTML 標記。 如果此項目包含子項目,將只會保留那些子項目中的文字。

例外狀況

指定的項目不能包含文字 (例如 IMG 項目)。

範例

下列程式碼會使用 CreateElement 建立新的超連結,並使用 屬性將文字指派給連結 InnerText

private void AddUrlToTooltip(string url)
{
    if (webBrowser1.Document != null)
    {
        HtmlElement elem = webBrowser1.Document.CreateElement("A");
        elem.SetAttribute("HREF", url);
        elem.InnerText = "Visit our Web site for more details.";

        webBrowser1.Document.Body.AppendChild(elem);
    }
}
Private Sub AddLinkToPage(ByVal url As String)
    If (WebBrowser1.Document IsNot Nothing) Then
        With WebBrowser1.Document
            Dim Elem As HtmlElement = .CreateElement("A")
            Elem.SetAttribute("HREF", url)
            Elem.InnerText = "Visit our web site for more details."

            .Body.AppendChild(Elem)
        End With
    End If
End Sub

備註

如果您嘗試將 HTML 指派給具有 InnerText 的專案,HTML 程式碼將會在檔中顯示為常值,就像您在文字檔中檢視 HTML 一樣。 如果您使用 屬性將 HTML 指派給專案, InnerText 將會傳 InnerHtml 回該 HTML 中已移除標記的所有文字。

指派值以 InnerText 終結屬於專案的任何子專案。

適用於

另請參閱