HtmlDocument.GetElementById(String) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
요소의 HtmlElement 특성을 검색 키로 사용하여 단일 ID 을 검색합니다.
public:
System::Windows::Forms::HtmlElement ^ GetElementById(System::String ^ id);
public System.Windows.Forms.HtmlElement GetElementById(string id);
public System.Windows.Forms.HtmlElement? GetElementById(string id);
member this.GetElementById : string -> System.Windows.Forms.HtmlElement
Public Function GetElementById (id As String) As HtmlElement
매개 변수
- id
- String
검색할 요소의 ID 특성입니다.
반품
지정된 값과 동일한 ID 특성을 가진 첫 번째 개체를 반환하거나 null 찾을 수 없는 경우 id 반환합니다.
예제
다음 코드 예제에서는 문서에서 명명 TABLE 된 검색 행 수를 계산 하 고 웹 페이지에 결과 표시 합니다. 코드 예제를 사용하려면 WebBrowser 프로젝트에 이름이 지정된 WebBrowser1컨트롤이 있고 해당 특성이 있는 웹 페이지를 TABLEID 로드해야 합니다 Table1.
private Int32 GetTableRowCount(string tableID)
{
Int32 count = 0;
if (webBrowser1.Document != null)
{
HtmlElement tableElem = webBrowser1.Document.GetElementById(tableID);
if (tableElem != null)
{
foreach (HtmlElement rowElem in tableElem.GetElementsByTagName("TR"))
{
count++;
}
}
else
{
throw(new ArgumentException("No TABLE with an ID of " + tableID + " exists."));
}
}
return(count);
}
Private Function GetTableRowCount(ByVal TableID As String) As Integer
Dim Count As Integer = 0
If (WebBrowser1.Document IsNot Nothing) Then
Dim TableElem As HtmlElement = WebBrowser1.Document.GetElementById(TableID)
If (TableElem IsNot Nothing) Then
For Each RowElem As HtmlElement In TableElem.GetElementsByTagName("TR")
Count = Count + 1
Next
Else
Throw (New ArgumentException("No TABLE with an ID of " & TableID & " exists."))
End If
End If
GetTableRowCount = Count
End Function
설명
문서에 ID 값 GetElementById 이 같은 요소가 여러 개 있는 경우 처음 찾은 요소가 반환됩니다.