<a href=“#”>

在html中看到这样的属性:<a href=“#”>搜了好久,感觉不甚明白,现记之,等遇到了再做补充。

 

 

# is called an anchor (or hash...). so the link is pointing to an anchor or ID on a page, or it would be if the # had some text after it. As it stands it goes nowhere because it doesn't have text after it.

In case you are wondering WHY a link would go nowhere, they are probably using "#" as a placeholder. An anchor tag would not behave as an anchor tag w/o the HREF, but setting an actual HREF might send you off the page each time you are testing. That is annoying, so "href='#'" works out nicely.

Addition tips. you can actually use # to jump to a specific part of ANOTHER page. for example let say somewhere in you "about.html" page you have an element with an ID= "theresMore". From any OTHER PAGE, you can link directly to that part of the page with "href=about.html#theresMore" ( do note that would be a relative url just for the example)

 

下面原文地址:http://blog.sina.com.cn/s/blog_3f8687af01000867.html

使用javascript的时候,通常我们会通过类似:
<a href="#" οnclick="javascript:方法">提交</a>
的方式,通过一个伪链接来调用javascript方法.这种方法有一个问题是:虽然点击该链接的时候不会跳转页面.但是滚动条会往上滚,解决的办法是返回一个false.


如下所示:
<a href="#" οnclick="javascript:方法;return false;">提交</a>


a href=#与 a href=javascript:void(0) 的区别
#包含了一个位置信息
默认的锚点是#top 也就是网页的上端而javascript:void(0)  仅仅表示一个死链接这就是为什么有的时候页面很长,浏览链接明明是#可是跳动到了页首
而javascript:void(0) 则不是如此,所以调用脚本的时候最好用void(0)或者<input onclick><div onclick>等


打开新窗口链接的几种办法
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)" οnclick="openWin(3,this)">杭州</a>
(注:该方法可以解决超级链接的onclick事件经过判断再设置href达到分类重定向的效果)

 

转载于:https://www.cnblogs.com/qiernonstop/p/3418449.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值