问题描述
我来自巴西,想知道如何在HTML页面中调用onClick
.
I'm from Brazil, and want to know how I can call onClick
in a HTML page.
使用Google Chrome浏览器,我收到了以下代码:
Using Google Chrome, I got this code:
<img src="Imagens/lupa.gif" alt="Pesquisar Pasta" class="img" onclick="localizar();">
我正在使用此VBA代码:
And I'm using this VBA code:
Sub FazerLoginSite()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.application")
With IE
.Visible = True
.Navigate ("https://webseal.itau/j146/pjuridico/")
While .Busy Or .ReadyState <> 4: DoEvents: Wend
On Error Resume Next
.document.getElementById("username").Focus
.document.getElementById("username").Value = "987268556"
.document.getElementById("password").Focus
.document.getElementById("password").Value = ""
.document.All("button1").Click
On Error GoTo 0
While .Busy Or .ReadyState <> 4: DoEvents: Wend
While .Busy Or .ReadyState <> 4: DoEvents: Wend
.document.getElementById("pasta").Focus
.document.getElementById("pasta").Value = "140200586125"
While .Busy Or .ReadyState <> 4: DoEvents: Wend
While .Busy Or .ReadyState <> 4: DoEvents: Wend
Set allInputs = IE.document.getElementsByTagName("input")
For Each element In allInputs
If element.getAttribute("src") = "Imagens/lupa.gif" Then
element.invokemember ("OnClick")
Exit For
End If
Next element
While .Busy Or .ReadyState <> 4: DoEvents: Wend
Debug.Print .LocationURL
End With
End Sub
所以,我不知道如何可以单击此代码,在网站上这是图像,而代码的第一部分是我设置的登录名和密码,我输入了一个要搜索的数字,这里称为"Pasta",最后我试图单击此图像.
So, I have no idea how do a can click on this code, In the web site this is a Image and the firts part of the code I set my login and password, the I put a number to search, here called "Pasta" , and finally I'm trying to Click on this image.
有人可以帮助我吗????对于任何英语问题,我们深表歉意.
Does anybody can Help me???? And sorry about any english problem.
推荐答案
不需要任何查找元素的元素.您可以使用execScript()
函数调用与onClick
相同的JavaScript函数:
There shouldn't be any need to find the element. You can just call the same JavaScript function that onClick
is calling using the execScript()
function:
IE.document.parentWindow.execScript "localizar();", "javascript"
这篇关于如何在HTML代码中使用VBA调用onClick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!