1,594
社区成员




unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, StdCtrls, MSHtml, IdBaseComponent,
IdComponent, IdTCPConnection, IdTCPClient, IdHTTP;
type
TForm1 = class(TForm)
wb1: TWebBrowser;
Button1: TButton;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
wb1.Navigate('http://localhost:12880/mtm/textarea.htm');
end;
procedure TForm1.Button1Click(Sender: TObject);
var
doc: IHTMLDocument2;
mTextArea: IHTMLTextAreaElement;
begin
doc := wb1.Document as IHTMLDocument2;
mTextArea := doc.all.item('offer-content',0) as IHTMLTextAreaElement;
mTextArea.value := 'abc';
end;
procedure TForm1.Button2Click(Sender: TObject);
var
doc: IHTMLDocument2;
mTextArea: IHTMLElement;
begin
doc := wb1.Document as IHTMLDocument2;
mTextArea := doc.all.item('offer-content',0) as IHTMLElement;
mTextArea.setAttribute('VALUE','ccc',0);
end;
end.
{实在是不懂, 只能帮顶了}
{弱弱问一句, 用 JS脚本可以不?}
//uses MSHTML, SHDocVw, ActiveX
doWithHtmlElement(aElementCollection:IHTMLElementCollection);
var
k:integer;
vk:oleVariant;
Dispatch: IDispatch;
HTMLInputElement:IHTMLInputElement;
HTMLSelectElement:IHTMLSelectElement;
HTMLOptionElement: IHTMLOptionElement;
HTMLTextAreaElement: IHTMLTextAreaElement;
HTMLFormElement:IHTMLFormElement;
HTMLOptionButtonElement:IHTMLOptionButtonElement;
begin
for k:=0 to aElementCollection.length -1 do
begin
Vk:=k;
Dispatch:=aElementCollection.item(Vk,0);
if Succeeded(Dispatch.QueryInterface(IHTMLInputElement,HTMLInputElement)) then
begin
With HTMLInputElement do
begin
if (UpperCase(Type_)='TEXT') or (UpperCase(Type_)='PASSWORD') then
begin
value:='text';
end
else if (UpperCase(Type_)='CHECKBOX') then
begin
checked:=true;
end
else if (UpperCase(Type_)='RADIO') then
begin
checked :=true;
end;
end;
end
else if Succeeded(Dispatch.QueryInterface(IHTMLSelectElement,HTMLSelectElement)) then
begin
With HTMLSelectElement do
begin
selectedIndex :=1;
end;
end
else if Succeeded(Dispatch.QueryInterface(IHTMLTEXTAreaElement,HTMLTextAreaElement)) then
begin
with HTMLTextAreaElement do
begin
value :='textarea';
end;
end
else if Succeeded(Dispatch.QueryInterface(IHTMLOptionElement,HTMLOptionElement)) then
begin
with HTMLOptionElement do
begin
end;
end
else if SUCCEEDED(Dispatch.QueryInterface(IHTMLFormElement,HTMLFormElement))then
begin
with HTMLFormElement do
begin
end;
end
else if SUCCEEDED(Dispatch.QueryInterface(IHTMLOptionButtonElement,HTMLOptionButtonElement))then
begin
end
else
;
end;
end;