首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将mshtml.IHTMLDivElement转换为mshtml.HTMLDivElementClass?

如何将mshtml.IHTMLDivElement转换为mshtml.HTMLDivElementClass?
EN

Stack Overflow用户
提问于 2012-02-10 15:35:54
回答 1查看 2.7K关注 0票数 1

如何将mshtml.IHTMLDivElement转换为mshtml.HTMLDivElementClass

代码语言:javascript
复制
IHTMLElementCollection collection = doc.body.all;

foreach (var htmlElem in collection)
{
    if (htmlElem is mshtml.IHTMLDivElement)
    {
         mshtml.IHTMLDivElement div = htmlElem as mshtml.IHTMLDivElement;
         if (div != null)
         {
            //  HTMLDivElementClass divClass = (HTMLDivElementClass)div;  ?????????                      
         }
     }            
}

我需要访问HTMLDivElementClass才能获得它的所有成员。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-03-07 05:38:31

你的代码几乎正确。不知道你想要什么。

请按以下方式更改代码

代码语言:javascript
复制
 mshtml.IHTMLElementCollection collection = (mshtml.IHTMLElementCollection)objDocument.body.all;

            foreach (var htmlElem in collection)
            {
                if (htmlElem is mshtml.IHTMLDivElement)
                {
                    mshtml.HTMLDivElementClass div = htmlElem as mshtml.HTMLDivElementClass;
                    if (div != null)
                    {
                    //DO YOUR CODE HERE 
                     //div.IHTMLElement_id
                    }
                }
            }

它为我工作,在"div“对象中,类型为"HTMLDivElementClass”。

还有一个建议,如果您只想从页面中获得所有的DIV标记,那么使用下面的代码行。

代码语言:javascript
复制
mshtml.IHTMLElementCollection collection = (mshtml.IHTMLElementCollection)objDocument.getElementsByName("div");

而不是

代码语言:javascript
复制
 mshtml.IHTMLElementCollection collection = (mshtml.IHTMLElementCollection)objDocument.body.all;

这将删除您的条件,以检查元素是否为DIV。

希望这对你有帮助。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9230284

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档