Share via


HtmlElementCollection.Item[] 屬性

定義

從集合中取得項目。

多載

Item[Int32]

藉由指定項目的數值索引從集合中取得項目。

Item[String]

藉由指定項目的名稱從集合中取得項目。

備註

HtmlElementCollection 物件是唯讀的。 若要將專案新增至 HTML 檔案,請使用 和 之類的 InsertAdjacentElementAppendChild 方法。

Item[Int32]

藉由指定項目的數值索引從集合中取得項目。

public:
 property System::Windows::Forms::HtmlElement ^ default[int] { System::Windows::Forms::HtmlElement ^ get(int index); };
public System.Windows.Forms.HtmlElement this[int index] { get; }
public System.Windows.Forms.HtmlElement? this[int index] { get; }
member this.Item(int) : System.Windows.Forms.HtmlElement
Default Public ReadOnly Property Item(index As Integer) As HtmlElement

參數

index
Int32

從集合中擷取項目的來源位置。

屬性值

藉由指定數值索引從集合中取得的項目。

備註

中的 HtmlElementCollection 元素不保證會以原始程式碼順序排列。 換句話說,只是因為 DIV 專案是標記內的 BODY 第一個專案,並不表示集合的第一個專案會是 DIV 元素。

適用於

Item[String]

藉由指定項目的名稱從集合中取得項目。

public:
 property System::Windows::Forms::HtmlElement ^ default[System::String ^] { System::Windows::Forms::HtmlElement ^ get(System::String ^ elementId); };
public System.Windows.Forms.HtmlElement this[string elementId] { get; }
public System.Windows.Forms.HtmlElement? this[string elementId] { get; }
member this.Item(string) : System.Windows.Forms.HtmlElement
Default Public ReadOnly Property Item(elementId As String) As HtmlElement

參數

elementId
String

項目的 NameId 屬性。

屬性值

HtmlElement (如果找到具名項目)。 否則為 null

範例

下列程式碼範例會 FORM 使用其名稱尋找 物件,並以程式設計方式將其資料提交至伺服器。 程式碼範例會要求您的應用程式裝載 WebBrowser 名為 的 webBrowser1 控制項。

private void SubmitForm(String formName)
{
    HtmlElementCollection elems = null;
    HtmlElement elem = null;

    if (webBrowser1.Document != null)
    {
        HtmlDocument doc = webBrowser1.Document;
        elems = doc.All.GetElementsByName(formName);
        if (elems != null && elems.Count > 0)
        {
            elem = elems[0];
            if (elem.TagName.Equals("FORM"))
            {
                elem.InvokeMember("Submit");
            }
        }
    }
}
Private Sub SubmitForm(ByVal FormName As String)
    Dim Elems As HtmlElementCollection
    Dim Elem As HtmlElement

    If (WebBrowser1.Document IsNot Nothing) Then
        With WebBrowser1.Document
            Elems = .All.GetElementsByName(FormName)
            If (Not Elems Is Nothing And Elems.Count > 0) Then
                Elem = Elems(0)
                If (Elem.TagName.Equals("FORM")) Then
                    Elem.InvokeMember("Submit")
                End If
            End If
        End With
    End If
End Sub

適用於