Home > Web Front-end > JS Tutorial > body text

Flag and jq on bind multiple objects and methods

高洛峰
Release: 2017-02-28 15:58:32
Original
1292 people have browsed it

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>
Copy after login

//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();
Copy after login

==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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template