About the way the plug-in is written, with the direction of this

    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/.

.
Mar.15,2021

1. There are two times of alert,. I think your code should have been executed twice. If your init is executed repeatedly, it will repeat the binding event
2 on element. The second question is that you write it incorrectly. The second parameter is a selector, not an element

.

clipboard.png

clipboard.png

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eb4555-4828b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eb4555-4828b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?