zoukankan      html  css  js  c++  java
  • js javascript:void(0)

    void keyword

    The void operator evaluates the given expression and then returns undefined.

    void expression 可以加()或者不加


    Javascript中void是一个操作符,该操作符指定要计算一个表达式但是不返回值。

    Uses

    This operator allows inserting expressions that produce side effects into places where an expression that evaluates to undefined is desired.

    The void operator is often used merely to obtain the undefined primitive value, usually using "void(0)" (which is equivalent to "void 0"). In these cases, the global variable undefined can be used instead (assuming it has not been assigned to a non-default value).

    JavaScript URIs

    When a browser follows a javascript: URI, it evaluates the code in the URI and then replaces the contents of the page with the returned value, unless the returned value is undefined. The void operator can be used to return undefined. For example:

    <a href="javascript:void(0);">Click here to do nothing</a>
    <a href="javascript:void(document.body.style.backgroundColor='green');">Click here for green background</a>
    

    Note, however, that the javascript: pseudo protocol is discouraged over other alternatives, such as unobtrusive event handlers.

    你以使用 void 操作符指定超级链接。表达式会被计算但是不会当前文档处装入任何内容。

    下面的代码创建了一个超级链接,当用户以后不会发生任何事。当用户链接时,void(0) 计算为 0,但 Javascript 上没有任何效果。

    <A HREF="javascript:void(0)">单此处什么也不会发生</A>

    下面的代码创建了一个超级链接,用户单时会提交表单。
    <A HREF="javascript:void(document.form.submit())">
    单此处提交表单</A>
    a href=#与 a href=javascript:void(0) 的区别 链接的几种办法

    #包含了一个位置信息

    默认的锚是#top 也就是网页的上端

    而javascript:void(0)   仅仅表示一个死链接

    这就是为什么有的时候页面很长浏览链接明明是#是

    跳动到了页首

    而javascript:void(0) 则不是如此

    所以调用脚本的时候最好用void(0)

    <script>
    function openPage(obj)
    {
    obj.target='_blank';
    obj.href="http://www.baidu.com";
    }
    </script>
    </head>

    <body>
    <a href="javascript:void(0);" onclick="openPage(this)">open</a>

    当点击open时会新打开一个标签页,显示百度。如何点击一次打开2个。

    我们可以函数还加一个obj.click();还调用一次点击,就可以还打开一个标签页。

     

  • 相关阅读:
    1001. A+B Format
    1011. World Cup Betting
    1015. Reversible Primes
    1005. Spell It Right
    1020. Tree Traversals
    java初始
    lvds接口介绍
    优化对比度增强的实时图像视频去雾
    JavaScript通过attachEvent和detachEvent方法处理带参数的函数
    Chrome类似于Firefox Firebug的功能
  • 原文地址:https://www.cnblogs.com/youxin/p/2738971.html
Copyright © 2011-2022 走看看