Figure 2 calls the function in Figure 1, and the output is Undefined, but in Figure 2, the same code is used in the JQ click event and the output result is. Then I declared a variable obj in the test function to obtain all objects with the attribute name=component_checkbox[]. At this time, there is output when calling this function in the JQ click event. My question is why the test() in Figure 2 does not output the result but is undefined when the code in Figure 1 is used?
Replace picture 2 with this:
MDN - Function.prototype.call
Because the scope of this is different, this in the click closure refers to the checkbox you selected, and in the test function, this refers to the window or other object
In Figure 1,
$(this)
has no pointing value