jquery.mobile.js tap事件执行两次
2018-03-06 09:52
253 查看
今天做一个点击选中,再次点击取消选中的功能,但是发现偶尔会点击一下tap方法却执行了两次,搞得我头疼,调了半天bug没找到原因,最后加了一个return false发现好了,可能是事件冒泡的问题。$(".list-group").on("tap","li",function(event){
event.stopPropagation();
var length = $(this).find(".glyphicon").length;
if (length>0){//选中状态下
$(this).removeClass("choose");
$(this).find(".glyphicon").remove();
}else {
$(this).addClass("choose");
$(this).find("span:eq(0)").after('<span class="glyphicon glyphicon-ok-circle" aria-hidden="true" style="font-size: 1.1em;color: #f3cc0c"></span>')
}
return false;
});
event.stopPropagation();
var length = $(this).find(".glyphicon").length;
if (length>0){//选中状态下
$(this).removeClass("choose");
$(this).find(".glyphicon").remove();
}else {
$(this).addClass("choose");
$(this).find("span:eq(0)").after('<span class="glyphicon glyphicon-ok-circle" aria-hidden="true" style="font-size: 1.1em;color: #f3cc0c"></span>')
}
return false;
});
相关文章推荐
- jQuery.tap.js插件tap事件执行两次问题
- 最近一段时间在使用zepto.js的tap事件的时候,出现执行两次的bug,并报错
- (转载)js(jquery)的on绑定点击事件执行两次的解决办法
- jquery mobile page事件执行顺序
- JQUERY $() $(document).ready() 事件执行两次解决办法。
- javascript 点击事件执行两次js问题
- 微信小程序改变app.js中页面位置 bindtap执行两次
- zepto.js tap 会执行两次的bug以及 Uncaught TypeError
- js的onclick和jquery的bind事件执行先后顺序
- Jquery 事件执行两次
- 关于jquery中 的点击事件,每点一次执行的效果就叠加一次,click是添加点击事件的意思
- 前端JS面试题汇总 Part 1(事件委托/this关键字/原型链/AMD与CommonJS/自执行函数)
- jquery结合js实现动态添加内容,并给动态添加的内容添加事件
- Jquery双击事件不触发执行单击事件解决方法
- js判断手机和pc端选择不同执行事件的方法
- jQuery页面加载后执行的事件(3种方式)
- html,js一个元素做两次不同点击事件
- 为在js jquery中添加的标签添加点击事件
- jquery实现点击触发执行不同的事件
- 史上最全的CSS hack方式一览 jQuery 图片轮播的代码分离 JQuery中的动画 C#中Trim()、TrimStart()、TrimEnd()的用法 marquee 标签的使用详情 js鼠标事件 js添加遮罩层 页面上通过地址栏传值时出现乱码的两种解决方法 ref和out的区别在c#中 总结