zoukankan      html  css  js  c++  java
  • jquery 实现在事件完成后才能再次点击执行

            var doing=false;//定义一个全局变量 (在事件完成后才能再次点击执行)
                            $(".zan-btn").on("click",function(){
                                if(doing){
                                    layer.msg("上一个操作未完成,请稍等!");
                                }else{
                                    doing=true;//变量设为true,表示开始操作
                                    var that = this
                                    var upvoteStatus=$(that).attr("data-upvoteStatus")
                                    if(upvoteStatus==0){
                                        sendReq("addUpvote","post","/shop/course/query",{id:videoId},function(res){
                                            if(res.status==1){
                                            // $(that).addClass("ele-hidden")
                                            // $(that).siblings(".no-zan").removeClass("ele-hidden")
                                            // var zanNum = Number.parseInt($(that).find('.zan-number').text())
                                            var zanNum=$(".upvoteNumber").text()
                                            $(".upvoteNumber").text(Number.parseInt(zanNum)+1)
                                            layer.msg("点赞成功",{icon:1})
                                            $(".icon-zan-video").addClass("icon-zan1 text-red").removeClass("icon-zan")
                                            $(".zan-btn").attr("data-upvoteStatus",1)
                                            doing=false; //变量改回false 表示结束操作
                                            }else if(res.status==-1){
                                                layer.msg(res.msg,{icon:2})
                                                doing=false; //变量改回false 表示结束操作
                                            }
                                        })
                                    }else if(upvoteStatus==1){
                                        sendReq("updateUpvote","post","/shop/course/query",{id:videoId},function(res){
                                            if(res.status==1){
                                            var zanNum=$(".upvoteNumber").text()
                                            $(".upvoteNumber").text(Number.parseInt(zanNum)-1)
                                            layer.msg("已取消点赞",{icon:1})
                                            $(".icon-zan-video").addClass("icon-zan").removeClass("icon-zan1 text-red")
                                            $(".zan-btn").attr("data-upvoteStatus",0)
                                            doing=false; //变量改回false 表示结束操作
                                            }else if(res.status==-1){
                                                layer.msg(res.msg,{icon:2})
                                                doing=false; //变量改回false 表示结束操作
                                            }
                                        })
                                    }
                                }
                            })
  • 相关阅读:
    OAuth 2.0 访问新浪、腾讯的资源服务器
    OAuth 2.0 Authorization Code授权方式详解
    linux权限补充:rwt rwT rws rwS 特殊权限
    异步服务器框架设计
    vsftpd常规操作指南
    folly学习心得
    中国人口趋势(19902035)
    hbase系统搭建
    过载保护
    穷人和富人
  • 原文地址:https://www.cnblogs.com/chenshaoxiong/p/13555643.html
Copyright © 2011-2022 走看看