jquery中click点击一下触发两次的解决办法

1.事件点击div触发两次事件办法

$("#myDiv").click(function(e){
 e.stopPropagation();   //表示阻止向父元素冒泡
 e.preventDefault();     //阻止 方法阻止元素发生默认的行为(例如,当点击提交按钮时阻止对表单的提交或者a标签)。
});

2.ajax时成功的触发click事件 如果多次ajax就会有多个事件存放,然后你点击时,会触发你点击的ajax的数目的click事件。
解决的办法是:$(“.at-share-btn”).unbind(); 提前取消事件

$.ajax({
                    type: "POST",
                    url:"/index.php",
                    data:{"email":email},
                    dataType:'json',
                    cache:false,
                    error: function(request) {
                        alert("Please refresh the page and try again.");
                    },
                    success: function(data) {
                    if(data.over){
                               $(".at-share-btn").unbind();
                               $(".at-share-btn").click(function(){  share(); });
                    }
                });

你可能感兴趣的:(jquery中click点击一下触发两次的解决办法)