How to click a link from javascript

后端 未结 3 710
时光取名叫无心
时光取名叫无心 2020-12-12 04:46

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done?

Thanks

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-12 05:14

    With JQuery It would be like this.

    $("#YOUR_A_TAG_ID").click();
    

    This only fires the function assigned to the click event. It will not navigate to the path specified in the href attribute.

    JQuery documentation for click

提交回复
热议问题