网页内容:
<select id="selTitle" name="selTitle" onchange="doSelTitle(this)"></select>请问下怎么调用这个ONCHANGE方法,我调用老是报"对象是空";
var hdoc:ihtmldocument2;
hall:ihtmlelementcollection;
hlen,tmploop:integer;
vk:oleVariant;
dispatch:IDispatch;
aSel:IHTMLSelectElement;if Assigned(webborwser) then
begin
hdoc:=webborwser.document as ihtmldocument2;
hall:=hdoc.get_all;
hlen:=hall.get_length;
for tmploop:=0 to hlen-1 do
begin
vk:=tmploop;
dispatch:=hall.item(vk,0);
if dispatch<>nil then
begin
if succeeded(Dispatch.QueryInterface(IHTMLSelectElement,aSel)) then
begin
if (uppercase(aSel.name)=uppercase('selTitle')) then
begin
aSel.selectedIndex:=1;
try
aSel.onchange:=hdoc.parentWindow.execScript('doSelTitle(this)', 'javascript'); //这里写this也报错;问题在这
except
end;
end;
end;
end;
end;
end;
<select id="selTitle" name="selTitle" onchange="doSelTitle(this)"></select>请问下怎么调用这个ONCHANGE方法,我调用老是报"对象是空";
var hdoc:ihtmldocument2;
hall:ihtmlelementcollection;
hlen,tmploop:integer;
vk:oleVariant;
dispatch:IDispatch;
aSel:IHTMLSelectElement;if Assigned(webborwser) then
begin
hdoc:=webborwser.document as ihtmldocument2;
hall:=hdoc.get_all;
hlen:=hall.get_length;
for tmploop:=0 to hlen-1 do
begin
vk:=tmploop;
dispatch:=hall.item(vk,0);
if dispatch<>nil then
begin
if succeeded(Dispatch.QueryInterface(IHTMLSelectElement,aSel)) then
begin
if (uppercase(aSel.name)=uppercase('selTitle')) then
begin
aSel.selectedIndex:=1;
try
aSel.onchange:=hdoc.parentWindow.execScript('doSelTitle(this)', 'javascript'); //这里写this也报错;问题在这
except
end;
end;
end;
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
WebBrowser1.OleObject.document.parentWindow.MB(); //如需指定脚本语言, 需要:
WebBrowser1.OleObject.document.parentWindow.execScript('MB()','JavaScript');
end;
假如有这样的脚本:
<script>
function MB(){
alert('你好');
}
</script>