Does JS judge multiple clicks on the same button?

as shown in the figure, there are four sort buttons in a table header, and the requirements are as follows: the first click on descending order, the second click on ascending order, and the third click on the default display (no sorting);
I would like to ask if there is a way to determine the three click states of the four buttons?
. I thought for a moment that if I realized it, I would have to use a more troublesome method, and I felt that it was very low~~

.
Feb.27,2021

try the trinomial expression


record each click and switch status values can be recorded on clickdom (data-state)

<div id="dom1" data-state="1" >xx</div>
$("-sharpdom1").click(){
   var state =  $(this).data('state')
    if(state == 1){
     .....
    }else if(){
     .....
    }
}

and do not affect each other


3 states, such as data-type 345 represents default, descending and ascending order. Judge the current status when you click. And request the corresponding sort result. Update data-type. after the request is completed Data-type= ((data-type+1)% 3) + 3.


because the four states cannot influence each other, all can only be judged by four variables, so it should be a good practice for data-id plus ternary expressions. If a variable, it will definitely influence each other


Why not sort it the third time? Datatable can sort each column in ascending or descending order.

Menu