简体   繁体   English

解析html页面后触发单击事件

[英]Trigger click event after parsing html page

I can programmatically go to an url, get the response and parse it. 我可以通过编程方式转到网址,获取响应并解析它。 But can I trigger the javascript click event of an html element of that response? 但是,我可以触发该响应的html元素的javascript click事件吗? For example, let's say the response contains an element: 例如,假设响应包含一个元素:

<div id="test">Click me</div>

And the page handles the click event like: 该页面处理click事件,如:

$("#test").on('click'..... etc. $("#test").on('click'..... etc.

So, is there a way that I can trigger that event after I get the html response? 那么,有没有一种方法可以在我获得html响应后触发该事件?

DOM elements have a .click() DOM元素有一个.click()

So, something like this works: 所以,像这样的工作:

 <body>
    <a href="" id="myLink">Test me!</a>
</body>

And then you have this: 然后你有这个:

// basic function to be called
function clickMe() {
  alert("Clicked!");
}

$(document).ready(function() {

  // click event handler
  $("#myLink").on('click', function() {
    clickMe();
  });

  // invoke the click
  $("#myLink").click();

});

I hope this helps. 我希望这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM