`procedure Focus(Document:IHTMLDocument2); var IDisp:IDispatch; pElement:IHTMLElement; i:integer; begin for I := 0 to Document.all.length - 1 do // 遍历所有HTML元素 begin {得到当前的IDispatch接口} IDisp:=Document.all.item(i,i); IDisp.QueryInterface(IID_IHTMLElement,pElement); if CompareText(pElement.tagName, 'INPUT ')=0 then begin Document.parentWindow.execScript(Format( 'document.all(%d).focus(); ',[i]), 'JScript '); {执行JavaScript,将焦点移动到该元素上} exit; end; end; // for end;
Document.parentWindow.execScript('document.getElementById(''id'').focus','javascript');`
procedure Focus(Document:IHTMLDocument2);
var IDisp:IDispatch;
pElement:IHTMLElement;
i:integer;
begin
for I := 0 to Document.all.length - 1 do // 遍历所有HTML元素
begin
{得到当前的IDispatch接口}
IDisp:=Document.all.item(i,i);
IDisp.QueryInterface(IID_IHTMLElement,pElement);
if CompareText(pElement.tagName, 'INPUT ')=0 then
begin
Document.parentWindow.execScript(Format( 'document.all(%d).focus(); ',[i]), 'JScript ');
{执行JavaScript,将焦点移动到该元素上}
exit;
end;
end; // for
end;
---
Document.parentWindow.execScript('document.getElementById(''id'').focus','javascript');