如何调用OnChange事件的“选择” ? (Delphi - WebBrowser) [英] How to call the OnChange event of "Select" ? (Delphi - WebBrowser)
本文介绍了如何调用OnChange事件的“选择” ? (Delphi - WebBrowser)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Delphi和WebBrowser componenet导航html页面。该页面有一个Combobox。有什么办法可以调用OnChange事件?
I'm using Delphi and WebBrowser componenet to navigate a html page . the page have a Combobox . is there any way to call the OnChange event ?
ComboBox是这样的:
The ComboBox is like this :
<select name="comboname" onchange="Some Javascript codes">
此外,我已使用此代码:
Also , i have used this code :
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
方法
to execute the onchange
event you can use the execScript
method
检查此示例
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;
了解更多信息查看此优秀文章
for more info check this excellent article
- How to call JavaScript functions in a TWebBrowser from Delphi
这篇关于如何调用OnChange事件的“选择” ? (Delphi - WebBrowser)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文