網頁代碼:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建網頁 1</title>
<script>
function aa(){
alert("abc");
}
</script>
</head>
<body>
<form method="POST" action="--WEBBOT-SELF--">
<p><input type="button" value="按鈕" name="B3" οnclick="aa()"></p>
</form>
</body>
</html>
delphi判斷網頁中是否存在某個名字的控件
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, StdCtrls, MSHTML_TLB;
type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Math;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
WebBrowser1.Navigate('c:\index.htm');
end;
procedure TForm1.Button1Click(Sender: TObject);
var b:IHTMLElement;
begin
b:=(WebBrowser1.Document as IHTMLDocument3).getElementById('B3');
if b=nil then exit;//這裏判斷網頁中是不是找到了這個按鈕,如果換成B4就不能執行下面的代碼了
b.click;
end;
end.