<div id="div1">divaa</div>
已经获得了IHTMLDocument2,input可以获得,但div要怎么获取呢?CComPtr < IHTMLDocument2 > pHtmlDoc;

解决方案 »

  1.   

    遍历所有的子element,判断class或id是否是div的
      

  2.   

    [size=60px]字体[/size]
      

  3.   

    IHTMLDocument3::getElementsByTagName(CComBSTR(L"DIV"));
      

  4.   

    我用的是VC6,没有IHTMLDocument3,而且页面没有form<html>
    <body>
    <div id="div1">divaa </div>
    </body>
    </html>现在取得
    CComQIPtr< IHTMLDocument2 > spDoc=m_ctrlWeb.GetDocument();
    BSTR bstr;
    IHTMLElement   *elBody   =   NULL;
    spDoc->get_body(&elBody);
    后面是怎么取?
      

  5.   

    CComPtr<IHTMLElementCollection> spAll;
    hr = spDoc->get_all(&spAll);
    CComVariant varID = LPCOLESTR("DIV");
    CComPtr<IDispatch> lpdisp;
    hr = spAll->item(varID,CComVariant(0),&lpdisp);
      

  6.   

    接下来
    CComPtr<IHTMLElement> item;
    lpdisp->QueryInterface(&item);就获得了DIV的IHTMLElement
      

  7.   

    ringphone
    =======
    你好,请问一下得到了DIV的IHTMLElement以后,怎么操作这个变量,比如修改DIV的属性等
      

  8.   

    http://www.codeproject.com/KB/cpp/DHTMLEditor.aspx
    你直接用这里面封装好的cHtmlElement等类即可
    例如
    cHtmlElement -> div
    cHtmlTable -> table
    cHtmlStyle -> css
      

  9.   

    不用第三方类,直接通过IHTMLDocument2或别的API去修改网页的属性,请问用什么方法
      

  10.   

    你可以调用IHTMLElement的put_XXX和setAttribute方法,查一下MSDN就知道了。
      

  11.   

    ringphone 
    ------
    你好,我用你指点的方法还是不能取得DIV,请问这是什么原因,我是在VS2008下调试的
      

  12.   

    熟悉JS的话你就知道了,按照JS里操作DOM的办法,根据ID获取 element