我已經證明了它是可以手動火從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