HtmlDocument.GetElementById("$id")
我想用這種方法與$id
獲得元素,但它meta
標籤匹配與具有相同的價值$id
的屬性。C#爲什麼方法HtmlDocument.GetElementById匹配標記的屬性名稱?
的HTMLDocument是這樣的:
<html>
<head>
<meta name="description" content="">
</head>
<body>
<div id="description"></div>
</body>
</html>
我試圖獲取標記div
與 「說明」 ID:
HtmlElement elem = doc.GetElementById("description");
但我得到meta
而不是div
。爲什麼meta
標籤匹配?
看起來你正在運行到[這](http://www.456bereastreet.com/archive/200802/beware_of_id_and_name_attribute_mixups_when_using_getelementbyid_in_internet_explorer/)。歡迎來到IE – StuartLC 2015-03-19 04:49:29
@StuartLC可能就在這裏。 [GetElementById]的C#實現(https://msdn.microsoft.com/en-us/library/system.windows.forms.htmldocument.getelementbyid(v = vs.110).aspx?cs-save-lang = 1&cs -lang = jscript#code-snippet-1)位於共享庫中,JScript也使用這個共享庫,這是JScript引擎在發佈該文章時使用的js引擎。假設它仍然沒有被修復,那可能是你現在遇到的同樣的問題。 – Matt 2015-03-19 05:48:09
謝謝。@ StuartLC @Matt – lauriezzc 2015-03-19 05:56:13