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

How to determine whether jquery is equal

藏色散人
藏色散人Original
2020-12-18 09:11:173034browse

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');
}

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" );
};

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")

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!

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