function simulateClick() { var evt = document.createEvent("MouseEvents"); evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); var cb = document.getElementById("checkbox"); var canceled = !cb.dispatchEvent(evt); if(canceled) { // A handler called preventDefault alert("canceled"); } else { // None of the handlers called preventDefault alert("not canceled"); }
Dim oDoc As HTMLDocument Set oDoc = pDisp.Document
Dim oInput As HTMLInputElement Set oInput = oDoc.getElementsByName("user")(0) oInput.FireEvent "onkeypress"
引用Microsoft HTML Object Libary
早上自己解决了``谢谢楼上的`` Dim vDoc, vTag Dim I As Integer Set vDoc = WB1.Document For I = 0 To vDoc.All.length - 1 If UCase(vDoc.All(I).tagName) = "INPUT" Then Set vTag = vDoc.All(I) If vTag.Type = "text" Then Select Case vTag.Name Case "username" '如果是用户名的那个框 vTag.Value = "用户名" '这个是用户名 vTag.onkeypress End Select
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, window,
0, 0, 0, 0, 0, false, false, false, false, 0, null);
var cb = document.getElementById("checkbox");
var canceled = !cb.dispatchEvent(evt);
if(canceled) {
// A handler called preventDefault
alert("canceled");
} else {
// None of the handlers called preventDefault
alert("not canceled");
}
Set oDoc = pDisp.Document
Dim oInput As HTMLInputElement
Set oInput = oDoc.getElementsByName("user")(0)
oInput.FireEvent "onkeypress"
Dim vDoc, vTag
Dim I As Integer
Set vDoc = WB1.Document
For I = 0 To vDoc.All.length - 1
If UCase(vDoc.All(I).tagName) = "INPUT" Then
Set vTag = vDoc.All(I)
If vTag.Type = "text" Then
Select Case vTag.Name
Case "username" '如果是用户名的那个框
vTag.Value = "用户名" '这个是用户名
vTag.onkeypress
End Select
End If
End If
Next I