我正在使用 Delphi 和 WebBrowser 组件来导航 html 页面。该页面有一个 Combobox 。有什么办法可以调用OnChange事件吗?
组合框是这样的:
<select name="comboname" onchange="Some Javascript codes">
另外,我已经使用了这段代码:
function TFrmMain.SetComboboxValue(WB: TEmbeddedWB;
SelectName, ItemName: string): Boolean;
var
iForms, iFormItems, iSelectItems: Word;
FormItem: OleVariant;
begin
Result := false;
for iForms := 0 to WB.OleObject.Document.Forms.length - 1 do
begin
FormItem := WB.OleObject.Document.Forms.item(iForms);
for iFormItems := 0 to FormItem.length - 1 do
begin
if (FormItem.item(iFormItems). type = 'select-one') and SameText
(FormItem.item(iFormItems).Name, SelectName) then
begin
for iSelectItems := 0 to FormItem.item(iFormItems).Options.length - 1 do
begin
if SameText(FormItem.item(iFormItems).Options.item(iSelectItems)
.Text, ItemName) then
begin
FormItem.item(iFormItems).SelectedIndex := iSelectItems;
Result := true;
Break;
end;
end;
end;
end;
end;
end;
但它只改变值。
最佳答案
要执行onchange
事件,您可以使用 execScript
方法
检查此示例
uses
MSHTML;
var
Doc: IHTMLDocument2;
HTMLWindow: IHTMLWindow2;
begin
Doc := WebBrowser1.Document as IHTMLDocument2;
if not Assigned(Doc) then
Exit;
HTMLWindow := Doc.parentWindow;
if not Assigned(HTMLWindow) then
Exit;
HTMLWindow.execScript('yourfunctioname()', 'JavaScript');
end;
有关更多信息,请查看这篇精彩的文章
关于html - 如何调用 "Select"的OnChange事件? (Delphi - 网络浏览器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3724822/