`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;javascript
Document.parentWindow.execScript('document.getElementById(''id'').focus','javascript');`java
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');