delphi怎样实现点击网页中的一个按钮
1个回答
展开全部
注意,需要uses ActiveX;
另外,附上测试用的test.htm 如下:
HTML code
<html><head><title>test</title></head><body><form name="F1" method="POST" action="c:\test.htm"><p><input type="text" name="T1" size="20"><input type="button" value="按钮" name="B3" onclick="alert('B3 be Clicked!')"><input type="submit" value="提交" name="B1"><input type="reset" value="全部重写" name="B2"></p></form></body></html>
Delphi(Pascal) code
procedure TForm1.Button1Click(Sender: TObject);
begin
Self.WebBrowser1.Navigate('c:\test.htm');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Self.WebBrowser1.OleObject.document.all.item('F1',0).submit; {提交}
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
Self.WebBrowser1.OleObject.document.all.item('T1',0).value := Self.Edit1.Text; {填充}
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
Self.WebBrowser1.OleObject.document.all.item('B3',0).click; {点击}
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
Self.WebBrowser1.OleObject.document.all.item('F1',0).reset; {重置}
end;
另外,附上测试用的test.htm 如下:
HTML code
<html><head><title>test</title></head><body><form name="F1" method="POST" action="c:\test.htm"><p><input type="text" name="T1" size="20"><input type="button" value="按钮" name="B3" onclick="alert('B3 be Clicked!')"><input type="submit" value="提交" name="B1"><input type="reset" value="全部重写" name="B2"></p></form></body></html>
Delphi(Pascal) code
procedure TForm1.Button1Click(Sender: TObject);
begin
Self.WebBrowser1.Navigate('c:\test.htm');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Self.WebBrowser1.OleObject.document.all.item('F1',0).submit; {提交}
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
Self.WebBrowser1.OleObject.document.all.item('T1',0).value := Self.Edit1.Text; {填充}
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
Self.WebBrowser1.OleObject.document.all.item('B3',0).click; {点击}
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
Self.WebBrowser1.OleObject.document.all.item('F1',0).reset; {重置}
end;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询