Skip to content

Instantly share code, notes, and snippets.

@Arguseye
Created September 11, 2014 04:11
Show Gist options
  • Select an option

  • Save Arguseye/cb2e1d0d69765b78d2f0 to your computer and use it in GitHub Desktop.

Select an option

Save Arguseye/cb2e1d0d69765b78d2f0 to your computer and use it in GitHub Desktop.
a标签href使用规则
一般情况下,使用link标签而只希望响应事件后什么都不做,所以将href设置为"#",但是:
设置为"#"会出现页面跳到页首,和url变化的问题,影响用户体验,于是可以使用"###"代替"#",让浏览器不能识别这个锚,but
这个仅仅解决了页面跳到页首的问题,但是没有解决url改变的问题,实在不希望用户看到让他们疑惑的东西,为什么url改变了,
所以可以使用href="javascript:void(0);",出自https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/void,but
mozilla有时会不考虑IE的感受,有时候会不兼容ie加载,所以可以使用javascript:;作为href的值,这样最好啦!貌似!哈哈
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment