HtmlElementCollection.Item[] 属性

定义

从集合中获取项。

重载

名称 说明
Item[Int32]

通过指定集合的数字索引从集合中获取项。

Item[String]

通过指定集合的名称从集合中获取项。

注解

HtmlElementCollection 对象是只读的。 若要向 HTML 文档添加元素,请使用诸如和InsertAdjacentElementAppendChild方法。

Item[Int32]

Source:
HtmlElementCollection.cs
Source:
HtmlElementCollection.cs
Source:
HtmlElementCollection.cs
Source:
HtmlElementCollection.cs
Source:
HtmlElementCollection.cs

通过指定集合的数字索引从集合中获取项。

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]

Source:
HtmlElementCollection.cs
Source:
HtmlElementCollection.cs
Source:
HtmlElementCollection.cs
Source:
HtmlElementCollection.cs
Source:
HtmlElementCollection.cs

通过指定集合的名称从集合中获取项。

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

元素 Name 的或 Id 属性。

属性值

如果找到命名元素,则为 />。 否则为 null

示例

下面的代码示例使用其名称查找对象 FORM ,并以编程方式将其数据提交到服务器。 该代码示例要求应用程序托管名为 /a0> 的 控件。

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

适用于