The this pointer in jQuery's each method points to a problem, which is a problem encountered during work yesterday. write the each statement: 1: Java code jQuery (& amp; #39; input [typecheckbox] & amp; #39 ;). each (function () {alert (this. checked + this. treeId); // tre
This pointer in jQuery's each method points to a problem, which was encountered during work yesterday.
JQuery. each statement:
1:
Java code
JQuery ('input [type = checkbox] '). each (function (){
Alert (this. checked + this. treeId); // treeI is a custom attribute.
});
JQuery ('input [type = checkbox] '). each (function (){
Alert (this. checked + this. treeId); // treeI is a custom attribute.
});
This method works normally in IE, but it is not recognized in firefox. Especially for custom attributes, this pointer has errors in closures.
2:
Java code
JQuery. each (jQuery ('input [type = checkbox] '), function (I, item ){
Alert ("I =" + I + ", item =" + jQuery (item). attr ('custom attribute '));
});
JQuery. each (jQuery ('input [type = checkbox] '), function (I, item ){
Alert ("I =" + I + ", item =" + jQuery (item). attr ('custom attribute '));
});
This will avoid using the this pointer, so it can be compatible with ie and firefox. I represents the first variable, and item represents the object referred to by this variable, which is a dom object.
Therefore, I personally recommend that you use the second method in jQuery's each method in the future.