Javascript 如何在sammyjs中找到引发事件的元素?
假设我有以下标记Javascript 如何在sammyjs中找到引发事件的元素?,javascript,sammy.js,Javascript,Sammy.js,假设我有以下标记 <ul class="app-nav"> <li><a href="#!/testing">Link to testing route</a> </ul> ... <a href="#!/testing">Other link to testing route</a> 使用sammy.js this.get('#!/testing', function(context) { //how
<ul class="app-nav">
<li><a href="#!/testing">Link to testing route</a>
</ul>
...
<a href="#!/testing">Other link to testing route</a>
使用sammy.js
this.get('#!/testing', function(context) {
//how I can get the event sender?
});
使用jQuery将请求绑定到文档并检查目标属性:
$(document).on('click', function( e ){
var sender = e.target; // <-- Your event initiator
});
根据文件,这似乎是你要找的
这是我的目标
保存此上下文的事件源自的DOM元素。对于post、put和del路由,这是触发路由的表单元素
因此,对于post请求,您可以从提交的表单中获取序列化对象
this.post('#:id', function() {
// this.target is the DOM form element that triggered the route
console.log($(this.target).serialize());
});
this.post('#:id', function() {
// this.target is the DOM form element that triggered the route
console.log($(this.target).serialize());
});