jQuery: trigger click() doesn't work?

前端 未结 6 655
面向向阳花
面向向阳花 2020-12-05 20:28

Why clicking on trigger1 and trigger2 doesn\'t fire click on open ?



        
6条回答
  •  无人及你
    2020-12-05 21:27

    It's important to clarify that doing jQuery('#open').click() does not execute the href attribute of an anchor tag so you will not be redirected. It executes the onclick event for #open which is not defined.

    You can accomplish the redirect and the ability to cause it with your original jQuery('#open').click() code by giving #open a click event:

    jQuery('#open').click( function (e) {
      window.location.href = this.href;
    });
    

提交回复
热议问题