HTML date picker with no input field. use VBA to fire update event
好的,
一个简单的问题,一个困难的解决方案(当前)
有一个页面,其中包含一个to和from日期选择器。 日期选择器没有html输入元素,但我可以使用InnerText访问它。
使用InnerText将to和from日期放入其中没有问题
出现这样的问题:
When dates are manually entered, a"form" appears, that updates live as the user chooses the dates, and displays only the data within that date range. When this is done programatically there is no live updating of the"form"
到目前为止的尝试:
1 2 3 4 5 6 7 8 9 | Set document = objIE.document With document .getElementsByClassName("controls").Item(0).Focus .getElementsByClassName("select-daterange").Item(0).Focus .getElementsByClassName("select-datepicker from").Item(0).Focus .getElementsByClassName("date-label").Item(0).innerText ="June 1, 2017" .getElementsByClassName("date-label").Item(1).innerText ="June 5, 2017" End With |
感谢社区的任何指导!
以下是日期选择器的示例:
我已经证明可以使用
一些链接在这里
Mozilla开发人员网络-EventTarget.fireEvent
这是我的代码。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | 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测试文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | <html> <head/> <body> <input id="source" type="text" onChange="MyChange('source')"></input> <input id="someOtherControlToFocusSwitchTo" type="text" value="foo"></input> function MyChange(eleId) { if (eleId) { var ele = document.getElementById(eleId); if (ele) { alert(ele.value); } } else { alert("MyChange fired with no param"); } } </body> </html> |
在其他地方,似乎有一种使用
1 2 3 4 5 | ' Fire the onChange event... Dim objEvent Set objEvent = doc.createEvent("HTMLEvents") objEvent.initEvent"change", False, True e.dispatchEvent objEvent |
我希望对您来说足够了,调试这些东西可能很棘手。