The following jquery code, why immediately after off. On?

function businessEvent(){
      var that = this;
    $(".business .business_item").each(function() {
        $(this).hover(function() {
            $(this).addClass("active");
        }, function() {
            $(this).removeClass("active");

        })
    }).off().on("click", function() {
        var businessType = $(this).attr("data-index");
        var name = $(this).attr("data-name");
        $(".business").attr("style","display:none");
        $(".business_navigation").attr("style","display:block");
        $.ajax({
            type : "post",
            url : "../hf/client/setBusinessType",
            dataType : "json",
            timeout:60000,
            async : false,
            data : {
                businessType:businessType,
                customerSessionId:sessionStorage.customerSessionId
            },
            success : function(resp) {
                
            }
        });
    });
  }
Jul.12,2021

in this way, businessEvent can be called multiple times without having to worry about adding an additional click event for each call.


add events to the clicked dom after unbinding all the events, which are generally used in the loop to avoid binding redundant events and causing multiple execution.

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-1e45c5e-43eb7.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-1e45c5e-43eb7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?