它适用于其他按钮,但如果这里的问题是嵌套的doPostBack和许多按钮,我就会工作。 (取而代之的是"")?
下面的代码(我已经删除了不相关的部分)
VBA代码:
Sub IE_Clicks()
Dim shellWins As ShellWindows
Dim IE As InternetExplorer
Set shellWins = New ShellWindows
If shellWins.Count > 0 Then
' Get IE
Set IE = shellWins.Item(0)
IE.Visible = True
Else
' Create IE
Set IE = New InternetExplorer
IE.Visible = True
End If
IE.Navigate ("[URL]")
Do While (IE.Busy Or IE.READYSTATE <> READYSTATE.READYSTATE_COMPLETE)
DoEvents
Loop
Call IE.document.parentWindow.execScript("WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions('ctl00$cphMain$btnAddTab', '', true, '', '', false, false))", "JavaScript")
Set IE = Nothing
End Sub
HTML代码:
<input type="submit" name="ctl00$cphMain$btnAddTab" value="Add New" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$cphMain$btnAddTab", "", true, "", "", false, false))" id="ctl00_cphMain_btnAddTab" class="ActionButton">
JavaScript的:
<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['aspnetForm'];
if (!theForm) {
theForm = document.aspnetForm;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
//]]>
</script>
使我能够点击此按钮的东西会很棒。
答案 0 :(得分:1)
这应该有效:
IE.document.getElementById("ctl00_cphMain_btnAddTab").Click