`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');