Home > Web Front-end > JS Tutorial > How to determine whether jquery is equal

How to determine whether jquery is equal

藏色散人
Release: 2020-12-18 09:11:17
Original
3093 people have browsed it

Jquery method to determine equality: 1. Use the "if (a==b && a==c && a==d) {}" method to determine; 2. Use "$(this). data("lastClick")" method can be used to realize the judgment.

How to determine whether jquery is equal

The operating environment of this tutorial: windows7 system, jquery1.10.0 version. This method is suitable for all brands of computers.

Recommended: "jquery video tutorial"

Jquery method to determine whether they are equal:

Judge whether two strings are equal Equality:

Use identity (===) to judge (the value and type are consistent). If you use equality (==) to judge (the values ​​are consistent), there will be a misjudgment.

 var a = "1"; //字符串1
var b = 1; //数值1
var c = true; //布尔值1
var d = "1";
if (a==b && a==c && a==d) {
console.log('equality');
}
Copy after login

Judgement Whether two objects are equal:

html:
<a href="#" id="a">a</a>
<a href="#" id="b">b</a>
<script type="text/javascript">
$(function(){
$(&#39;#a&#39;).greenify();
});
</script>
js:
$.fn.greenify = function() {
    console.log(this.index());
    console.log($("#b").index());
    this.css( "color", "green" );
};
Copy after login

In this case, the first method can be judged by index().

The second method is to add a data attribute to the object for judgment.

$(this).data("lastClick")
Copy after login

The above is the detailed content of How to determine whether jquery is equal. For more information, please follow other related articles on 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