扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
LPDISPATCH lpDisp = GetHtmlDocument();
if (lpDisp)
...{
CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> spDoc(lpDisp);
if ( spDoc )
...{
CComPtr<IHTMLElement> spElem;
HRESULT hr = spDoc->createElement(L"applet", &spElem);
if ( FAILED(hr) || !spElem )
return;
CComPtr<IHTMLElement> pBodyElem;
hr = spDoc->get_body(&pBodyElem);
if ( FAILED(hr) || !pBodyElem )
return;
CComPtr<IHTMLDOMNode> pBodyNode(pBodyElem);
if ( !pBodyNode )
return;
CComPtr<IHTMLDOMNode> pNewChild(pElem);
CComPtr<IHTMLDOMNode> pRefChild;
hr = pBodyNode->appendChild(pNewChild, &pRefChild);
if ( FAILED(hr) || !pRefChild )
return;
CComQIPtr<IHTMLObjectElement, &IID_IHTMLObjectElement> pObj(pRefChild);
if ( pObj )
...{
//修改属性等等
}
}
}
<HTML>
<HEAD>
<SCRIPT>...
function createRadioButton()...{
// Create radio button object with value="First Choice" and then insert
// this element into the document hierarchy.
var newRadioButton = document.createElement("<INPUT TYPE='RADIO' NAME='RADIOTEST' VALUE='First Choice'>")
document.body.insertBefore(newRadioButton);
// Create radio button object with value="Second Choice" and then insert
// this element into the document hierarchy.
newRadioButton = document.createElement("<INPUT TYPE='RADIO' NAME='RADIOTEST' VALUE='Second Choice'>")
document.body.insertBefore(newRadioButton);
}
</SCRIPT>
</HEAD>
<BODY>
<INPUT TYPE="BUTTON" ONCLICK="createRadioButton()" VALUE="Create two Radio Buttons"><BR>
<INPUT TYPE="BUTTON" ONCLICK="alert ( document.body.outerHTML )" VALUE="Click here to see HTML">
<BODY>
</HTML>
LPDISPATCH lpDisp = GetHtmlDocument();
if (lpDisp)
...{
CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> spDoc(lpDisp);
if ( spDoc )
...{
CComPtr<IHTMLElement> spBodyElem;
HRESULT hr = spDoc->get_body(&spBodyElem);
if ( FAILED(hr) || !spBodyElem )
return;
//我们先创建网页元素,注意给一个ID
hr = spBodyElem->insertAdjacentHTML(L"beforeEnd", L"<applet code='RainbowText.class' ID='my applet' width='297' height='48' codebase='class/' name='rainbowText'><param name='TEXT' value='test' ></applet>");
if ( FAILED(hr) )
return;
//再通过IHTMLDocument3来访问它
CComQIPtr<IHTMLDocument3, &IID_IHTMLDocument3> spDoc3(lpDisp);
if ( !spDoc3 )
return;
CComQIPtr<IHTMLElement> spElemTemp;
hr = spDoc3->getElementById(L"my applet", &spElemTemp);
if ( FAILED(hr) || !spElemTemp)
return;
//把Applet作为IHTMLObjectElement来处理
CComQIPtr<IHTMLObjectElement, &IID_IHTMLObjectElement> pApplet(spElemTemp);
if ( pApplet )
...{
//这样就行了
}
}
}如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。