2017-06-29 24 views
0

嗨,大家好,我有一個小問題,中止鏈接重定向

我有一個設置圖標點擊事件,但設置圖標是一個鏈接裏面,所以當我點擊圖標點擊事件被稱爲但我看不到任何東西,因爲我被重定向到下一個頁面,所以我需要一種方法來點擊圖標兵不血刃的鏈接

<template name="startseite"> 
    <div id="viewport"> 
     {{#each gebiet}} 
     <div id="viewmode"> 
    this is the link--> <a id="link" href="/straßen/{{this._id}}"> 
       <div id="gebietsCard"> 
        <ul id="gebieteListe"> 
     and here the icon --> <li id="settings"><i id="setting" class="material-icons md-24 md-light">settings</i></li> 
         <li id="überschrift">{{Gebietsname}}</li> 
         <li>{{Gebietsnummer}}</li> 
         <li>{{Ort}}</li> 
        </ul> 
       </div> 
      </a> 
     </div> 
     <div id="editmode"> 
      <div id="gebietsCardEdit"> 
       test 
      </div> 
     </div> 
     {{/each}} 
    </div> 
</template> 

我的JS:

Template.startseite.events({ 
      'click #settings': function(){ 
       console.log("geklickt") 
      $("#editmode").css('display', 'inline'); 
      $("#viewmode").css('display', 'none'); 
    }  
}); 

我希望你能幫助我謝謝夥計們;)

回答

1

這可以很容易地做到:

Template.startseite.events({ 
    'click #settings': function(e){ 
    e.stopPropagation(); 
    e.preventDefault(); // I am not sure if this is needed, try it yourself and remove if it is no use 

    $("#editmode").css('display', 'inline'); 
    $("#viewmode").css('display', 'none'); 
    } 
} 

你可以找到關於這兩個功能在這裏更多的信息:

+0

完善它的工作原理,但如果你想用它與流星,你必須寫事件,而不是絕對t e。 – Michael

+0

hmm? 'e'只是一個變量名,你可以任意命名它 – Khang

+0

e實際上是一個'event'對象的實例。 –