一个IE窗口打开的页面中有两个文本框,我需要用一个程序来设置或提取该文本框的内容。我无html基础,请说得较为清楚详细些。

解决方案 »

  1.   

    http://topic.csdn.net/t/20020608/15/788611.html
      

  2.   

    这是一段伪代码,可以参考:
    function setInnerText (elementId, text) { 
       var element; 
       if (document.getElementById) { 
         element = document.getElementById(elementId); 
       } 
       else if (document.all) { 
         element = document.all[elementId]; 
       } 
       if (element) { 
         if (typeof element.textContent != 'undefined') { 
           element.textContent = text; 
         } 
         else if (typeof element.innerText != 'undefined') { 
           element.innerText = text; 
         } 
         else if (typeof element.removeChild != 'undefined') { 
           while (element.hasChildNodes()) { 
             element.removeChild(element.lastChild); 
           } 
           element.appendChild(document.createTextNode(text)); 
         } 
       } 
    } http://support.microsoft.com/kb/176792/en-us
    http://community.csdn.net/Expert/topic/5166/5166830.xml?temp=9.692019E-02
      

  3.   

    http://topic.csdn.net/t/20020608/15/788611.html
    找本书看看也好啊
      

  4.   

    CComPtr<IHTMLDocument3> pDoc3;
    hr = pDoc2->QueryInterface(IID_IHTMLDocument3,(void**)&pDoc3) ;
    if(hr==S_OK)
    {
    CComBSTR bstrName("INPUT");
    CComPtr<IHTMLElementCollection> pElemCollINPUT;
    hr=pDoc3->getElementsByTagName(bstrName,&pElemCollFrame);
    if (hr==S_OK)
    {
    long pLength;
    hr=pElemCollINPUT->get_length(&pLength);
    if(hr==S_OK)
    {
    for(int i=0;i<pLength;i++)
    {
    IDispatch *pDispInputText=NULL;
    CComVariant vIndex=i;
    hr=pElemCollINPUT->item(vIndex,vIndex,&pDispInputText);
    if(hr==S_OK)
    {
    CComPtr<IHTMLInputTextElement> pElemInputText;
    hr=pDispFrame->QueryInterface(IID_IHTMLInputTextElement,(void**)&pElemInputText); 
    if(hr==S_OK)
    {
        CComBSTR strVal;
        pElemInputText->get_value(&strVal);//得到文本值
        pElemInputText->put_value(strVaL);//设置文本值
    }
    }
    pDispInputText->Release();
    }
    }
    }
    }
      

  5.   

    void  TfrmMain::SetInputValue(AnsiString _sTitle, AnsiString _sContent)
    {
        AnsiString sType;
        IHTMLDocument2 *pDocument = NULL;
        IHTMLElementCollection *pCollection = NULL;
        IHTMLElementCollection *pInputCollection = NULL;
        IDispatch *dsInput = NULL;    if( lvNewWork->Selected == NULL ) return;
        if( S_OK!=CppWebBrowser1->Document->QueryInterface(IID_IHTMLDocument2,(void **)&pDocument) ) return;
        pDocument->get_all(&pCollection);
        if( pCollection==NULL ) goto return1;
        VARIANT var;
        var.vt = VT_BSTR;
        var.bstrVal = L"INPUT";
        pCollection->tags(var,&dsInput);
        if( dsInput == NULL ) goto return1;
        dsInput->QueryInterface( IID_IHTMLElementCollection, (void **)&pInputCollection);    long lInputCount;
        pInputCollection->get_length(&lInputCount);
        for( long l = 0; l < lInputCount; l++ )
        {
          _variant_t index = l;
            IDispatch* pDisp;
            HRESULT hr=pInputCollection->item(index,index,&pDisp);
            if( pDisp == NULL ) continue;
            IHTMLInputElement *pElement = NULL;
            pDisp->QueryInterface(IID_IHTMLInputElement,(void**)&pElement);
            if( pElement == NULL ) continue;
            BSTR bstemp;
            pElement->get_type(&bstemp);
            sType = bstemp;
            ::SysFreeString(bstemp);
            if( sType=="text")
            {
                pElement->get_name(&bstemp);
                sType = bstemp;
                ::SysFreeString(bstemp);
                int iType = GetInputType(sType);
                AnsiString sContent;
                if( iType == 1 )
                {
                    btnCopyTitleClick(btnCopyTitle);
                }
                else if( iType == 2)
                {
                    btnCopyTitleClick(btnContentCopy);
                }
                if( iType )
                {
                    sContent = Clipboard()->AsText;
                    //bstemp = TStringConverter<TCHAR>::AnsiToWide(sContent.c_str());
                    _bstr_t val(sContent.c_str());
                  pElement->put_value(bstemp);
                    //delete [] bstemp;
                }
            }
            pDisp->Release();
            pElement->Release();    }
    return1:
    if( pDocument )pDocument->Release();
        if( pCollection ) pCollection->Release();
        if( dsInput ) dsInput->Release();
        if( pInputCollection ) pInputCollection->Release();
    }
      

  6.   

    通过IE的IHtmlDocument 接口逐步获取对应的IHtmlElement,然后取得属性Value值
      

  7.   

    http://www.vckbase.com/code/listcode.asp?mclsid=17&sclsid=1711
    里面有原代码,参考一下