我通过vba代码操作IE,添加了一个按钮,并且绑定了onclick()对象,但是点击无效。网页本身固有的按钮有效。
Sub vba添加元素()
Dim roIe As Object
Set roIe = CreateObject("internetExplorer.application")
roIe.Visible = True
roIe.Navigate ("c:\linshi.html")
Do Until roIe.ReadyState = 4
DoEvents
Loop
Stop
Set doc = roIe.Document
Set ele3 = doc.createElement("input")
ele3.Value = "new"
ele3.ID = "new"
ele3.onclick = "tt()"
ele3.Type = "button"
doc.body.appendChild (ele3)
'doc.getElementById("new").Click '这样操作也无效
End Sub
linshi.html
<html>
<head>
<script type="text/javascript">
function tt() {
alert("fafaf");
}
</script>
</head>
<body>
<input id="3" type="button" value="tt" onclick="tt()"><br>
</body>
</html>