Home  >  Article  >  Web Front-end  >  Flag and jq on bind multiple objects and methods

Flag and jq on bind multiple objects and methods

高洛峰
高洛峰Original
2017-02-28 15:58:321284browse

Why is $(this) in the function in jquery not equal to $(e.target)?

//html中有个按钮:
 <button id="myBtn">我的按钮</button>
<script>
$('#myBtn').click(function(e){ 
 console.log($(this));
 console.log($(e.target));
 console.log($(this)==$(e.target)); 
}); 
</script>

//Found that $(this) and $(e.target)
//The contents printed on the console are exactly the same
//However, the two are not equal

Because jq is used to construct the two objects, when you compare in the last step, even if the contents of the two objects are exactly the same, the result will not wait. Object The comparison compares pointers. The two pointers are different, so we don’t want to wait. Simply put,

var a = new Object();
var b = new Object();

==The two objects look like They are exactly the same, but I still don’t want to wait for the comparison result==

Directly compare this == e.target in order to get the correct result==

The above flag is tied to jq on Defining multiple objects and methods is all the content the editor has shared with you. I hope it can give you a reference, and I also hope you will support the PHP Chinese website.

For more articles related to flag and jq on binding multiple objects and methods, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn