Alternative to when the anchor tag only triggers a jQuery action without redirecting the user?

后端 未结 10 1171
走了就别回头了
走了就别回头了 2021-02-09 15:57

I have numerous anchor tags on my page that only trigger jQuery actions on the same page.

The don\'t redirect the user to another location, which is the normal expected

10条回答
  •  攒了一身酷
    2021-02-09 16:44

    If the anchor is useless to people who don't have javascript, then they shouldn't see it at all.

    The best alternative is to generate these links using jQuery on page load - that way the only people who see them are those who will use them.

    In this case, having href="#" is fine, because as long as your event handler finishes with return false; then the href will never be followed

提交回复
热议问题