[英]Ran into some troubles when using waypoints and jquery $(this)
我正在使用最新的航点库。 每次路点通过program-block
,都应将属性data-index
的值记录到控制台,但每次发生时,它都会输出undefinded
。
我该如何处理?
<div class="program-block" data-index="1"></div>
<div class="program-block" data-index="2"></div>
<div class="program-block" data-index="3"></div>
<div class="program-block" data-index="4"></div>
<div class="program-block" data-index="1"></div>
var waypoints = $('.program-block').waypoint({
handler: function(direction) {
console.log($(this).data('index'));
}
});
这是我的代码 (但没有工作示例):
这里是航点网站的链接 :
在Waypoint 3中, this
不是对HTML元素的引用。 它是对Waypoint实例的引用。 要访问基础元素,必须使用this.element
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.