如何从 Internet Explorer DOM 调用 javascript
我正在使用 VBA (Excel) 来操作 Internet Explorer 中加载的网页中的下拉框。下拉框附加了一些 JavaScript,以便当下拉选择更改时页面的 UI 控件也会更改。
我使用下面的函数(自动)从下拉列表中选择一个选项。它会更改下拉框的值,但不会触发 UI 更改(与我手动更改下拉框时相比)。
Sub selectFromDropdown(ByRef dropdown As HTMLSelectElement, ByVal optionName As String)
Dim opts
Dim opt As HTMLOptionElement
dropdown.Focus
dropdown.setCapture
Set opts = dropdown.children
For i = 1 To opts.Length
Set opt = opts.Item(i)
If opt.Text = optionName Then
opt.Selected = True
dropdown.selectedIndex = opt.Index
Exit For
End If
Next
dropdown.releaseCapture
End Sub
那么我怎样才能触发附加到这个下拉框的javascript呢?或者一般来说,如何通过 MS Internet Explorer 提供的 API 以编程方式触发事件?谢谢。
I'm using VBA (Excel) to manipulate a dropdown box in web page loaded in Internet Explorer. The dropdown box has some javascript attached so that the page's UI controls will change when the dropdown selection is changed.
I use the below function to (automatically) select an option from the dropdown. It changes the value of the dropbox but it does not trigger the UI changes (as compared to when I manually change the dropdown box).
Sub selectFromDropdown(ByRef dropdown As HTMLSelectElement, ByVal optionName As String)
Dim opts
Dim opt As HTMLOptionElement
dropdown.Focus
dropdown.setCapture
Set opts = dropdown.children
For i = 1 To opts.Length
Set opt = opts.Item(i)
If opt.Text = optionName Then
opt.Selected = True
dropdown.selectedIndex = opt.Index
Exit For
End If
Next
dropdown.releaseCapture
End Sub
So how can I trigger the javascript that is attached to this dropdown box? Or in general, how can I fire an event programmatically via the API provided by MS Internet Explorer? Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该显示足够的 HTML,以便我们可以看到附加的 javascript 和事件类型。
假设这是一个“onclick”,
你可以有
You should show enough HTML that we can see the javascript attached and the type of event.
Lets say it is an "onclick"
You could have
当您设置组合框值时显式调用您的 javascript 函数。
call your javascript function explicitly when you set combobox value.