mshtml fireevent onchange 未触发

标签 mshtml microsoft.mshtml

我无法在 mshtml 中触发“onchange”事件。你能告诉我我在这里做错了什么吗?

HTMLSelectElement element = (HTMLSelectElement)this.HTMLDocument.all.item(controlId, 0);
IHTMLElement e = element as IHTMLElement;
IHTMLDocument4 doc = e.document as IHTMLDocument4;
object dummy = null;
object eventObj = doc.CreateEventObject(ref dummy);
HTMLSelectElementClass se = element as HTMLSelectElementClass;
se.FireEvent("onchange", ref eventObj);

我将变量“se”设置为空。我从另一个链接http://www.itwriting.com/phorum/read.php?3,1507得到了这段代码

谁能帮我解决这个问题。

谢谢, 山姆

最佳答案

由 COM 调用(如 HTMLDocument.all.item)生成的运行时可调用包装对象可以将接口(interface)转换转换为 QueryInterface 调用。但 RCW 不知道如何转换为像 HTMLSelectElementClass 这样的托管类,因此它返回 null。

不要转换为 HTMLSelectElementClass,而是转换为 IHTMLElement3 来调用 fireEvent。

顺便说一句,您的代码无法在 IE11 模式下运行,因为 document.all 已被弃用。请改用 IHTMLDocument3::getElementById。

关于mshtml fireevent onchange 未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30641304/

相关文章:

visual-c++ - 在 MSHTML 中获取当前用户选择 (IHTMLTxtRangePtr)

c++ - 使用 MSHTML 如何将焦点设置在输入字段上?

vba - HTMLCanvasElement 类型不匹配

c# - 使用 explorer.document 作为 HtmlAgilityPack 的源 HtmlDocument

internet-explorer - 在IE中hook http/https协议(protocol)导致GET请求是顺序的

c# - 为什么 MSHTML for .Net 没有 querySelector 和 querySelectorAll,或者它们在哪里?

delphi - 如何让 TWebBrowser 忽略其他控件的加速器字符?

css - 数据 uri :s 的 MSHTML 回退