HtmlElement.TagName Właściwość

Definicja

Pobiera nazwę tagu HTML.

public:
 property System::String ^ TagName { System::String ^ get(); };
public string TagName { get; }
member this.TagName : string
Public ReadOnly Property TagName As String

Wartość właściwości

String

Nazwa użyta do utworzenia tego elementu przy użyciu znaczników HTML.

Przykłady

Poniższy przykład kodu znajduje wszystkie IMG tagi w dokumencie i używa TagName właściwości do testowania, czy IMG obiekt jest hiperlinkowany do innej strony. Jeśli tak jest, kod przypisuje adres URL do ALT atrybutu tagu IMG , aby użytkownicy mogli przejmieć obraz, aby zobaczyć, gdzie zostaną one zabrane.

private void AddUrlToTooltip()
{
    if (webBrowser1.Document != null)
    {
        foreach (HtmlElement elem in webBrowser1.Document.GetElementsByTagName("IMG"))
        {
            if (elem.Parent.TagName.Equals("A"))
            {
                String altStr = elem.GetAttribute("ALT");
                if (!(altStr == null) && (altStr.Length != 0))
                {
                    elem.SetAttribute("ALT", altStr + " - points to " + elem.Parent.GetAttribute("HREF"));
                }
                else
                {
                    elem.SetAttribute("ALT", "Points to " + elem.Parent.GetAttribute("HREF"));
                }
            }
        }
    }
}
Private Sub AddUrlToTooltip()
    If (WebBrowser1.Document IsNot Nothing) Then
        With WebBrowser1.Document
            For Each Elem As HtmlElement In .GetElementsByTagName("IMG")
                If (Elem.Parent.TagName.Equals("A")) Then
                    Dim AltStr As String = Elem.GetAttribute("ALT")
                    If (Not (AltStr Is Nothing) And (AltStr.Length <> 0)) Then
                        Elem.SetAttribute("ALT", AltStr & " - points to " & Elem.Parent.GetAttribute("HREF"))
                    Else
                        Elem.SetAttribute("ALT", "Points to " & Elem.Parent.GetAttribute("HREF"))
                    End If
                End If
            Next
        End With
    End If
End Sub

Uwagi

Wiele elementów w modelu obiektów dokumentów HTML ma atrybuty, właściwości i metody, które są unikatowe dla tych elementów; HREF na przykład atrybut w elemecie A lub metodzie w elemecie Submit FORM. Użyj TagName polecenia , jeśli masz element potencjalnie dowolnego typu i musisz wykonać operację specyficzną dla typu.

Dotyczy

Zobacz też