如何调用&QUOT OnChange事件,选取[ ? (德尔福 - web浏览器) [英] How to call the OnChange event of "Select" ? (Delphi - WebBrowser)

查看:105
本文介绍了如何调用&QUOT OnChange事件,选取[ ? (德尔福 - web浏览器)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Delphi和web浏览器componenet浏览HTML页面。该页面有一个组合框。有没有办法来调用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">

另外,我已经使用这个code:

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;

但它只能改变数值。

But it change the value only.

推荐答案

执行的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

这篇关于如何调用&QUOT OnChange事件,选取[ ? (德尔福 - web浏览器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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