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

前端 未结 14 1563
说谎
说谎 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:10

    void is an operator that is used to return a undefined value so the browser will not be able to load a new page.

    Web browsers will try and take whatever is used as a URL and load it unless it is a JavaScript function that returns null. For example, if we click a link like this:

    Click Me
    

    then an alert message will show up without loading a new page, and that is because alert is a function that returns a null value. This means that when the browser attempts to load a new page it sees null and has nothing to load.

    An important thing to note about the void operator is that it requires a value and cannot be used by itself. We should use it like this:

    I am a useless link
    

提交回复
热议问题