• Home >Web Front-end >JS Tutorial >Example analysis of the true meaning of javascript:void(0)_javascript skills

    Example analysis of the true meaning of javascript:void(0)_javascript skills

    WBOY
    WBOYOriginal
    2016-05-16 19:01:411103browse

    When you look at JavaScript scripts, you can often see code like this:
    〈a href="javascript:doTest2();void(0);"〉here〈/a〉
    But what exactly is void(0) here? What does it mean?
    void is an operator in JavaScript, which specifies that an expression is to be evaluated but does not return a value.

    void operator usage format is as follows:
    1. javascript:void (expression)
    2. javascript:void expression

    expression is a JavaScript standard expression to be calculated . The parentheses outside the expression are optional, but it is a good practice to write them.

    You can specify a hyperlink using the void operator. The expression is evaluated but nothing is loaded into the current document.

    The following code creates a hyperlink that does nothing when the user clicks on it. When the user clicks the link, void(0) evaluates to 0, but has no effect on JavaScript.

    The difference between void and #

    # contains a location information. The default anchor point is #top, which is the top of the web page, while javascript:void(0) only represents a dead link.

    This is why sometimes the browsing link on a very long page jumps to the top of the page even if it is #, but this is not the case with javascript:void(0), so it is best to use void(0) when calling the script.

    Statement:
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn