var pay={
int:function(options){
var that = this;
var settings = {
id:".news a",
yes:""
};
settings = $.extend(true, {}, settings, options);
var elem = $(settings.id);
elem.on("click",function(){
$.ajax({
type: "POST",
dataType: "json",
url:"",
success: function(res) {
if (typeof settings.yes === "function") {
//
settings.yes(data);
return;
}
}
})
});
}};
pay.int({
id:".news a",
yes:function(data){
alert("");
console.log(data);
}
});
< H2 > first question < / H2 >
Why does the alert, execute twice after the A tag is clicked? shouldn"t alert? wait until the ajax is completed? Immediately after clicking, execute alert ajax and alert again after completion
< H2 > second question. < / H2 >
pay.int({
id:".news a",
yes:function(data){
alert("");
console.log(data);
}
});
settings = $.extend(true, {}, settings, options);
var elem = $(settings.id);
elem.on("click",function(){
this newsA
})
$(document).on("click",elem,function(){
,thisid:".news a",
});
< H2 > third question. < / H2 >
is there a better way to write it.
the following is the test connection. If the title this is not obtained after the binding click time, it points to global
http://sandbox.runjs.cn/show/.