1.事件點(diǎn)擊div觸發(fā)兩次事件辦法
$("#myDiv").click(function(e){
e.stopPropagation(); //表示阻止向父元素冒泡
e.preventDefault(); //阻止 方法阻止元素發(fā)生默認(rèn)的行為(例如,當(dāng)點(diǎn)擊提交按鈕時(shí)阻止對(duì)表單的提交或者a標(biāo)簽)。
});
2.ajax時(shí)成功的觸發(fā)click事件 如果多次ajax就會(huì)有多個(gè)事件存放,然后你點(diǎn)擊時(shí),會(huì)觸發(fā)你點(diǎn)擊的ajax的數(shù)目的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(); });
}
});