菲纹卫生巾官方网站:HtmlDocument.GetElementById 方法

来源:百度文库 编辑:九乡新闻网 时间:2024/05/03 11:45:38

HtmlDocument.GetElementById 方法

.NET Framework 4 其他版本
  • .NET Framework 3.5
  • .NET Framework 3.0
  • .NET Framework 2.0

将元素的 ID 特性用作搜索键来检索单个 HtmlElement

 

命名空间:  System.Windows.Forms
程序集:  System.Windows.Forms(在 System.Windows.Forms.dll 中)语法
VB C# C++ F# JScript 复制
public HtmlElement GetElementById(string id)

参数

id
类型:System.String
要检索的元素的 ID 特性。

返回值

类型:System.Windows.Forms.HtmlElement
返回第一个与指定的值具有相同 ID 特性的对象;如果找不到 id,则返回 null。
备注

如果文档中有多个元素具有相同的 ID 值,GetElementById 将返回找到的第一个元素。

示例

下面的代码示例从文档中检索已命名的 TABLE,计算行数并将结果显示在网页中。 该代码示例要求项目中有一个名为 WebBrowser1 的 WebBrowser 控件,并且您已加载了一个网页,该网页包含一个 ID 特性为 Table1 的 TABLE。

VB C# C++ F# JScript 复制
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);}
平台

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求版本信息


.NET Framework

受以下版本支持:4、3.5、3.0、2.0

.NET Framework Client Profile

受以下版本支持:4
请参见

参考

HtmlDocument 类 HtmlDocument 成员 System.Windows.Forms 命名空间