a href 属性

两种用法:

页面跳转时使用 url (部分浏览器会阻止新窗口弹出页面),其他情况一律遵循          ‘结构样式行为分离’

1. url

href="#"     文档顶部    表示回到最顶部

href="https://www.baidu.com"   绝对地址    页面跳转

<a href="layout/flex_layout.html">文件链接</a>   相对地址   页面跳转(也可以是文件资源下载)     
href="#id"   锚点    回到页面中指定位置

2. js

href="javascript:js_method();"    会导致不必要的触发window.onbeforeunload事件,在IE里面更会使gif动画图片停止播放

a href="javascript:void(0);" onclick="js_method()"    void(0)返回undefined,地址不发生跳转

a href="javascript:;" onclick="js_method()"    

a href="#" onclick="js_method()"

<a href="#" onclick="js_method();return false;">顶部</a>    点击执行方法  不返回顶部
<a href="javascript:if(confirm('确认要删除吗?')){window.location.href='https://www.baidu.com'}">baidu</a>     执行代码段
原文地址:https://www.cnblogs.com/justSmile2/p/9844250.html