顺序
1.onclick和href的执行顺序
代码:
//会先执行jump()方法,然后执行href跳转到login.html页面
<a href="login/login.html" onclick = "jump();">点击跳转到login页面</a>
判断跳转
1.在jump中添加判断
//通过event.preventDefault取消跳转
<a href="login/login.html" onclick = "jump();">点击跳转到login页面</a>
function jump(){
if (!confirm("您确认要离开吗"))
event.preventDefault();
}
2.在onclick后面添加return false,取消href跳转
//只执行onclick事件
<a href="login/login.html" onclick = "jump();return flase">点击跳转到login页面</a>
跳转
1.利用javascript:void(0)取消跳转
<a href="javascript:void(0)" onclick="jump(this)">
2.利用# 等同于#top
<a href="#" onclick="jump(this)">