Js can set the same event event to have two click? And the questions raised by the js function?

question 1

$(".active-btn").click(function(e) {
    // do 1...
    // do 4...
});

$(".active-btn").click(function(e) {
    // do 2...
    // do 3...
});

I suddenly find this problem
my click event repeats
, but I can actually do these things separately.
although there is no repetition of the two things to be done
is it possible?

question 2
another question: is there any way to put forward the function in js function?

$(".btn").click(function(e) {

  switch (type) {
    case "a":
        // do a
        //  a.js 
    break;
    
    case "b":
        // do b
        //  b.js 
    break;
    
    case "c":
        // do c
        //  c.js 
    break;
  }
});

suppose there are three things to do
can I write three additional js of these three things and then introduce them into them?
is very much like php"s require or include.
introduces different files, but is doing what"s inside the files?
or something with similar effect?

additional questions three

clipboard.png

what"s the difference between these two kinds of introduction?

Jun.08,2022

first problem: jquery can bind multiple listening functions to a single event. Its underlying implementation is the same as using the native addEventListener . Only setting onClick attribute assignment will override the event.
second question: of course, you can do modular split, and there are many ways to deal with modules introduced in or ES6 natively supported import . The implementation is that the module is defined and output according to the rules, and then it can be loaded on demand.

Menu