1. 程式人生 > >前端學習代碼實例-JavaScript 阻止擊超鏈接的跳轉

前端學習代碼實例-JavaScript 阻止擊超鏈接的跳轉

div ont 依然 http www set javascrip 如何實現 soft

點擊鏈接具有跳轉效果,但是有時我們不需要這種效果。

下面就通過代碼實例介紹一下如何實現此效果。

代碼如下:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>web前端開發學習扣qun:731771211   詳細教程分享</title>
<style type="text/css">
div{
  width:150px;
  height:50px;
  margin:0px auto;
  margin-top:800px
}
</style>
</head>
<body>
<div><a href="#">學習前端,我們是認真的</a></div>
</body>
</html>

以上代碼雖然將鏈接地址設置為#,但是點擊之後依然有跳轉效果,網頁返回頂端。

代碼修改如下:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>學習前端,我們是認真的</title>
<style type="text/css">
div{
  width:150px;
  height:50px;
  margin:0px auto;
  margin-top:800px
}
</style>
</head>
<body>
<div><a href="#">學習前端,我們是認真的</a></div>
</body>
</html>

更多編程知識分享,關註v-x公眾號id:mtbcxx

前端學習代碼實例-JavaScript 阻止擊超鏈接的跳轉