html - 如何调用 "Select"的OnChange事件? (Delphi - 网络浏览器)

标签 html delphi combobox browser

我正在使用 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/

相关文章:

javascript - <div> 的透明区域使用 border-radius 不会触发 mouseleave?

asp.net - 尝试以各种可能的方式嵌入 SVG 对象,但浏览器在呈现 html 时提示保存文件

xml - 在 Delphi 中使用 XML 的教程在哪里?

java-me - 如何获取组合框的选定项目

Javascript循环 - 隐藏动画div

javascript - 以编程方式在 JavaScript 中获取和设置 jssor 的索引

web-services - 确保 Delphi 中 Web 服务中的功能是安全的

delphi - 如何启动使用官方 TTrayIcon (delphi) 最小化的应用程序?

c# - ComboBox 的 BindingSource 和 PropertyGrid 的 [Browsable(false)] 属性不能一起工作

wpf - 使用 MVVM Light 从组合框中的按钮触发命令