zepto.js - zepto Api 疑问:index() 和 indexOf() 具体怎么使用?
本文介绍了zepto.js - zepto Api 疑问:index() 和 indexOf() 具体怎么使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
var tm = $(".status-load > div");
var _this=$(this);
console.log($.index(tm));
tm.each(function(idx){
tm.eq(idx).on('tap',function(){
_this.addClass("load-chk")
.siblings().removeClass("load-chk")
.end();
if(_this.index()==0){
orderLists();
}else if(_this.index()==1){
orderUndone();
}else if(_this.index()==2){
orderUndo();
}
});
});
上面代码需要实现一个效果,就是被点击的元素添加样式的时候去判断元素的下标,如果下标相等,执行对应方法。
现在报了个错误
对这个具体事例看的不是很懂!
解决方案
var _this = $(this);
从Error Message 来看似乎是 $(this)
所指向的 element 没有 parentNode 造成的(具体原因要和 context 结合才能排查)
这篇关于zepto.js - zepto Api 疑问:index() 和 indexOf() 具体怎么使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文