\" tag in a html page ? like this : <span id=\"_ID_\">开发者_运维百科Hello There</span>" />
开发者

How to click on </span> Tag ? (Webbrowser - Delphi)

开发者 https://www.devze.com 2023-01-15 15:09 出处:网络
how can i click on a \"< / span>\" tag in a html page ? like this : <span id=\"_ID_\">开发者_运维百科Hello There</span>

how can i click on a "< / span>" tag in a html page ?

like this :

<span id="_ID_">开发者_运维百科Hello There</span>

Is it possible ? Thanks


I think you want to say "how can i call the click event on a span element ?". For a span element :

<span id="myId" onclick="myOnclikFunction()">Hello There</span>

In JavaScript you can simulate a click (seems work only on IE !) :

document.getElementById("myId").click();

With jQuery you can call the click event (and call the myOnclikFunction() function) on an element like this :

$('#myId').trigger("click");

or

$('#myId').click();

For information : id="_ID_" is not a HTML valid code. An id can't start by "_". It must begin with a letter A-Z or a-z (see HTML id Attribute).


You can do the following :

procedure TMainFrm.ClickBtnClick(Sender: TObject);
var
 Document : IHTMLDocument2;
 SPAN, Temp : IHTMLElement;
 ElementCount, I : Integer;
begin
 if WB.Document = nil then
  begin
   MessageBox(Handle, 'First Load a Page in TWebBrowser !!', '', MB_OK+MB_ICONEXCLAMATION);
   Exit;
  end;

 if SIDEdit.Text = '' then
  begin
   MessageBox(Handle, 'Enter SPAN ID !', '', MB_OK+MB_ICONEXCLAMATION);
   Exit;
  end;

 Document := WB.Document as IHTMLDocument2;
 ElementCount := Document.all.length;
 for I := 0 to ElementCount - 1 do
  begin
   Temp := Document.all.item(I, '') as IHTMLElement;
   if (Temp.tagName = 'SPAN') and (Temp.id = SIDEdit.Text) then
    begin
     SPAN := Temp;
     Break;
    end;
  end;
 if SPAN <> nil then
  SPAN.click
 else
  MessageBox(Handle, 'No SPAN Tag with ID Entered Found !', '', MB_OK+MB_ICONINFORMATION);
end;

Put this Components on the Form :

TWebBrowser , Name : "WB" , for browsing the page

TEdit , Name : "SIDEdit" , for giving the SPAN tag ID

TBitBtn , Name : "ClickBtn" , the Code above is the OnClick Event of "ClickBtn"

I Think that the Code is Simple and Variables are understandable , if necessary tell me to explain the Code ...

There is an Example ...

Good Luck ... !


inside span onclick="yourJsFunctionishere();

0

精彩评论

暂无评论...
验证码 换一张
取 消