如何在VBA中为Javascript中选定术语中的fireevent“ onchange”编写代码。它不能用作编码.querySelector(".zcq0.djhtm?b=Q&a= & var & ").FireEvent "onchange"
。有人可以帮忙吗,谢谢您?
Public Sub GetTWYIn()
Dim ie As Object, URL As String, var As Object, ele As Object, td As Date
Const max_wait_sec As Long = 10
Set var = ThisWorkbook.Worksheets("Sheet3").Cells(1, 1)
URL = "http://pscnetinvest.moneydj.com.tw/z/zc/zcq/zcqa/zcqa_" & var & ".djhtm"
Set ie = CreateObject("internetexplorer.application")
With ie
.Visible = True
.navigate URL
While .Busy Or .readyState < 4: DoEvents: Wend
With .document
b = Timer
Do
On Error Resume Next
Set ele = .querySelector("[value$='/zcq0.djhtm?b=Q&a=" & var & "']")
On Error GoTo 0
If Timer - td > max_wait_sec Then Exit Do
Loop While ele Is Nothing
If ele Is Nothing Then Exit Sub
ele.Selected = True
.querySelector(".zcq0.djhtm?b=Q&a= & var & ").FireEvent "onchange"
End With
End With
Set ie = Nothing`
End Sub
这是html。
<SELECT name="selB" id="selB" onchange="javascript:selopn(this.options[this.selectedIndex].value);">
<OPTION value="/z/zc/zcq/zcq0.djhtm?b=Q&a=1232" >季表</OPTION>
<OPTION value="/z/zc/zcq/zcq0.djhtm?b=A&a=1232" >累計季表</OPTION>
<OPTION value="/z/zc/zcq/zcq0.djhtm?b=Y&a=1232" selected>年表</OPTION>
</SELECT>