href=#与href=javascript:void(0)的区别

#"包含了一个位置信息,默认的锚点是#top 也就是网页的上端

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

这就是为什么有的时候页面很长浏览链接明明是#可是跳动到了页首,而javascript:void(0) 则不是如此

打开新窗口链接的几种办法

  1.window.open('url')

  2.用自定义函数

        <script>
        function openWin(tag,obj)
        {
            obj.target="_blank";
            obj.href = "Web/Substation/Substation.aspx?stationno="+tag;
            obj.click();
        }
        </script>

     <a  href="javascript:void(0)" onclick="openWin(3,this)">LINK_TEST</a>

  3.window.location.href=""

如果是个# ,就会出现跳到顶部的情况,个人收藏的几种解决方法:
1:<a href="####"></a>
2:<a href="javascript:void(0)"></a>
3:<a href="javascript:void(null)"></a>
4:<a href="#" onclick="return false"></a>
5:<span style="cursor:hand"></span>(好像在FF中不能显示)

原文地址:https://www.cnblogs.com/WebApp-DotNet/p/6432493.html