简体   繁体   English

在网页上触发组合框的 OnChange

[英]Triggering OnChange for combobox on webpage

I am working on an application that can fill out a form automatically.我正在开发一个可以自动填写表单的应用程序。 The issue I am having is that there are two comboboxes on the webpage.我遇到的问题是网页上有两个组合框。
Combobox1 has items that change depending on what is selected in Combobox2. Combobox1 的项目会根据在 Combobox2 中选择的内容而变化。
Combobox2 has items. Combobox2 有项目。
Combobox2 has the following code: Combobox2 具有以下代码:

onchange="javascript:setTimeout('__doPostBack(\'ctbnss_2103\',\'\')', 0)"

If I were to manually select an item in Combobox2, a loading gif pops up on the page, and once finished, Combobox1 has new items.如果我在 Combobox2 中手动选择一个项目,页面上会弹出一个加载 gif,完成后,Combobox1 有新项目。 This is the desired result.这是想要的结果。

If I select an item in Combobox2 through code, no loading gif pops up, and Combobox1 still has the old items even though a Combobox2 item has been successfully selected.如果我通过代码在 Combobox2 中选择一个项目,则不会弹出加载 gif,即使成功选择了 Combobox2 项目,Combobox1 仍然有旧项目。 This is my code:这是我的代码:

eoBrowserWV.EvalScript("frames['main'].document.getElementById('combobox2').value='" + stringItem1 + "';");

How do I adjust this code so that Combobox1 refreshes?如何调整此代码以便 Combobox1 刷新? I know that I have to somehow trigger the onchange event after changing Combobox2, but while I am successful in changing Combobox2, I am not sure what code I have to add after the above code, to fire OnChange.我知道我必须在更改 Combobox2 后以某种方式触发 onchange 事件,但是虽然我成功更改了 Combobox2,但我不确定在上述代码之后我必须添加什么代码来触发 OnChange。

I tried the below, without success, as it appears that .trigger is not a function:我尝试了以下操作,但没有成功,因为 .trigger 似乎不是一个函数:

wvMain.EvalScript("frames['main'].document.getElementById('combobox2').trigger('change');");

And I have also tried this, without success, due to this error: Uncaught TypeError: Failed to execute 'dispatchEvent' on 'EventTarget': parameter 1 is not of type 'Event'.'我也试过这个,但没有成功,因为这个错误:Uncaught TypeError: Failed to execute 'dispatchEvent' on 'EventTarget': parameter 1 is not type 'Event'.'

wvMain.EvalScript("frames['main'].document.getElementById('combobox2').dispatchEvent('change');");

解决了它:

wvMain.EvalScript("frames['main'].document.getElementById('combobox2').dispatchEvent(new Event('change'));");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM