HTML示例代码如下:
<script language="javascript">
<!--
function test(){
var obj=document.getElementById("test");
for(var i=0;i<6; i++){
var testDiv=document.createElement("div"); testDiv.setAttribute("id","son"+i);
testDiv.style.cursor="pointer";
testDiv.title=i;
testDiv.onclick=function(){alert(i);}
testDiv.innerHTML="No."+i;
obj.appendChild(testDiv);
}
}
//-->
</script>
<body onload="test()">
<div id="test"></div>
</body>
Delphi示例代码如下:
procedure TForm1.Button1Click(Sender: TObject);
var
Doc:IHTMLDocument2;
Fdiv:IHTMLElement;
begin
WebBrowser1.Navigate('http://127.0.0.1/test1.htm');
while WebBrowser1.ReadyState<>4 do
Application.ProcessMessages;
//
Doc:=WebBrowser1.Document as IHTMLDocument2;
Fdiv:=Doc.all.item('test',varEmpty) as IHTMLElement;
ShowMessage(Fdiv.innerText);
end;