What does “[removed]void(0)” mean?

前端 未结 14 1356
说谎
说谎 2020-11-21 15:23
login

I\'ve seen such hrefs many times, but I don\'t know what exactly

14条回答
  •  抹茶落季
    2020-11-21 16:05

    It is a very popular method of adding JavaScript functions to HTML links.
    For example: the [Print] links that you see on many webpages are written like this:

    Print
    

    Why do we need href while onclick alone can get the job done? Because when users hover over the text 'Print' when there's no href, the cursor will change to a caret (ꕯ) instead of a pointer (👆). Only having href on an a tag validates it as a hyperlink.

    An alternative to href="javascript:void(0);", is the use of href="#". This alternative doesn't require JavaScript to be turned on in the user's browser, so it is more compatible.

提交回复
热议问题