Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/420.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在sammyjs中找到引发事件的元素?_Javascript_Sammy.js - Fatal编程技术网

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());
});