2012-07-10 37 views
0

假設我有以下標記如何找出在sammyjs中發起事件的元素?

<ul class="app-nav"> 
    <li><a href="#!/testing">Link to testing route</a> 
</ul> 
... 
<a href="#!/testing">Other link to testing route</a> 

使用jQuery

$('a').click(function() { 
    console.log($(this)); //the event sender and can be 'a' or 'ul>li>a' 
}); 

隨着sammy.js

this.get('#!/testing', function(context) { 
    //how I can get the event sender? 
}); 

回答

0

使用jQuery您的要求綁定到文件和檢查目標屬性:

$(document).on('click', function(e){ 

    var sender = e.target; // <-- Your event initiator 

}); 
0

根據文檔,Event Context似乎是你在找什麼。

this.target

DOM元素即保持此上下文中事件從起源。對於post,put和del路由,這是觸發路由的表單元素。

因此,對於發佈請求,您可以從提交的表單中獲取序列化對象。

this.post('#:id', function() { 
    // this.target is the DOM form element that triggered the route 
    console.log($(this.target).serialize()); 
}); 
相關問題