How to use jquery trigger anchor's default click event?

前端 未结 5 1822
醉话见心
醉话见心 2021-01-06 12:57

Suppose I have an anchor in my page like :turn to header then I also set a button in my page

5条回答
  •  生来不讨喜
    2021-01-06 13:36

    Please see this answer.

    Instead of trying to trigger the click event, try setting the window.location property:

    window.location = '#header';
    

    Or perhaps:

    $("input").click(function() {
      window.location = $('#anchor').attr('href');
    });
    

提交回复
热议问题