我已经证明了它是可以手动火从VBA使用fireevent
Javascript事件。
这里
Mozilla Dev Network - EventTarget.fireEvent
一些链接这里是我的代码。
Option Explicit
Sub Test()
'* Tools->References->Microsoft HTML Object Library
'* Tools->References->Microsoft Internet Controls
Dim ie As SHDocVw.InternetExplorerMedium
Set ie = New SHDocVw.InternetExplorerMedium
ie.Visible = True
ie.navigate "n:\TestWebOnChangeManually.html"
Dim obj As Object
Stop '* i use this pause to dismiss Allow Block Content footer warning message
Dim dom As MSHTML.HTMLDocument
Set dom = ie.document
Dim textSource As MSHTML.HTMLInputElement
Set textSource = dom.getElementById("source")
textSource.innerText = "poked"
'https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/fireEvent
'* not sure what to place in second parameter
textSource.FireEvent "onchange", Nothing
End Sub
,并使用这个网站的测试文件
<html>
<head/>
<body>
<input id="source" type="text" onChange="MyChange('source')"></input>
<input id="someOtherControlToFocusSwitchTo" type="text" value="foo"></input>
<script>
function MyChange(eleId)
{
if (eleId)
{
var ele = document.getElementById(eleId);
if (ele) {
alert(ele.value);
}
} else
{
alert("MyChange fired with no param");
}
}
</script>
</body>
</html>
其他地方似乎有使用dispatchEvent
一些代码SO FireEvent and IE11复制,虽然我没有尝试这种不同的方法。这是基于在SO How can I trigger an onchange event manually?发现一些JavaScript VBA代码本身是SO How to trigger event in JavaScript?
' Fire the onChange event...
Dim objEvent
Set objEvent = doc.createEvent("HTMLEvents")
objEvent.initEvent "change", False, True
e.dispatchEvent objEvent
重复我希望这是够你调试这个东西可能会非常棘手。
IE11。我应该尝试Firefox吗? – user1
如果你不能共享URL,那么在页面上使用了什么'date-picker'?你能在这里更具体吗? – dee
http://alloyui.com/examples/datepicker/像这样。没有输入框,只选择日期 – user1