HtmlElementCollection.Item[] 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
從收藏中取得一件物品。
多載
| 名稱 | Description |
|---|---|
| Item[Int32] |
透過指定集合的數值索引來取得項目。 |
| Item[String] |
透過指定收藏名稱取得該收藏品。 |
備註
HtmlElementCollection 物件是唯讀的。 要在 HTML 文件中新增元素,請使用像 InsertAdjacentElement 和 AppendChild這樣的方法。
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
參數
屬性值
若找到該命名元素,則 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