如何调用“Select"的OnChange事件?(Delphi - 网页浏览器) [英] How to call the OnChange event of "Select" ? (Delphi - WebBrowser)

查看:28
本文介绍了如何调用“Select"的OnChange事件?(Delphi - 网页浏览器)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Delphi 和 WebBrowser 组件来导航 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 ?

组合框是这样的:

<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

这篇关于如何调用“Select"的OnChange事件?(Delphi - 网页浏览器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆