2017-05-25 55 views
0

我有一個項目的角度,每次你點擊一個標籤href =「#」,它被重定向到項目的開始。當你點擊帶有href =「#」的標籤時,不要重定向,也不會發生任何事情。我不想使用event.prevent或類似的東西,因爲那麼我應該把它放在每個HTML標籤上。 enter image description here點擊帶有href =「#」的標籤時不重定向。 Angular.js

<script type="text/ng-template" id="views/login.html"> 
    <h1>view with my problem</h1> 

    this link has href='#'. I need stop redirecting.. 
    Without using something 'event.prevent' like this because I do not want to do it every time 
      <br> 

    <a href="#">NOT REDIRECT!</a> 
</script> 

https://jsfiddle.net/0hdcb3dr/

我希望你找到的href = '#' 任何部位,不要重定向到默認模板($ urlRouterProvider.otherwise( '/'));不應該重定向,但我不想每次使用$ event.prevent或類似的東西時,我發現自己href ='#' 在一個真正的項目中,我到處都有href ='#',我不想修復它逐個。

+0

@MatiasCicero https://jsfiddle.net/33ujw8gj/ – yavg

回答

1

只需提供空href屬性:

<a href>NOT REDIRECT!</a> 

我已經更新了你的fiddle這種變化。

+0

我更新了更多細節......我需要做任何事href ='#' – yavg

+0

@yavg所以如果我是正確的,你想要一個'a href =#'不做任何事情?沒有任何JS防止它?我不認爲這是可能的。您必須使用Matias提供的方法,因爲它是實現您想要的唯一方法。 – jdmdevdotnet