In JS, the current object is generally represented by this, in jquery, the current object is expressed in $ (this), these are the most basic knowledge, nothing to say, but I would say, when this appears at a certain depth, it means you have to understand, It refers to the current object that is closest to the current element, not to another object.
This example
For example, in a function-represented class, it may have its own method inside, and this in the method represents the current method object, not the class object at the function level, the code is as follows
var cart=function() {var self=this; This is the current function object self. add=function() {var insertobj=this; This is the current Add method object }}
$ (This) example
For jquery is also a, such as in a click event, there is a $.post method, at this time, the $.post method of $ (this) and the method of $ (this) is two meaning, so if you want to use the Click Object in the $.post method of this, Generally need to declare outside the $.post method, the code is as follows
// Delete $ (". Deletebtn"). Click (function () { var = $ (this); the current Click event Source Object $.post ("/course/delcourse?id=" + $(thisfunction ( Data) { if (Data.code = = 1) { self.closest ("Div.titdefault"). Remove (); }); });
Js~this's Trap