2014-11-07 169 views
3

我在我的網頁瀏覽器中有一個像下面這樣的頁面,我希望獲得style atributte值。我想:如何獲取網頁瀏覽器元素的CSS樣式?

HtmlElement ele = webBrowser1.Document.GetElementById("foo"); 
      MessageBox.Show(ele.GetAttribute("style")); 

但它輸出:

System.__ComObject 

爲什麼它輸出System.__ComObject型,我如何處理呢?

HTML頁面:

<div id="foo" style="display:block;"> 
a 
</div> 

回答

3
ele.Style 

會有所幫助。

ele.GetAttribute("Style") 

不會因爲回報串的工作,所以也不能說更重要的是是一個對象,而​​返回CssStyleCollection

3
var e = document.getElementById('foo'); 
var css = window.getComputedStyle(e,null).getPropertyValue("display"); 
alert(css); 
+0

這也是非常有用的。 Thansk! – Jack 2014-11-07 03:32:24

相關問題