Home > Web Front-end > JS Tutorial > JQuery returns Boolean value Is() conditional judgment method code_jquery

JQuery returns Boolean value Is() conditional judgment method code_jquery

WBOY
Release: 2016-05-16 17:53:38
Original
1076 people have browsed it

The following is JQuery's Is() method judgment;

Copy code The code is as follows:

$( function(){
$("ul").click(function(event){
var tar = event.target;
if(tar.tagName == "STRONG"){
alert (tar.tagName);
}
});
})

The above is the native JS judgment;
Copy code The code is as follows:

$(function(){
$("ul").click(function(event){
var tar = event.target;
if($(tar).is("strong")){
alert(tar.tagName);
}
});
})

Most of the methods in JQuery return the JQuery diagonal. The Is() method returns a Boolean value;
Difference:
$(tar): Pack the tar object into A jquery object. Only in this way can jquery methods be used; $(tar).is("strong"): Use the Is() method to judge;

Use of is method in jQuery

is() is used to detect whether there are matching elements.
Explanation in the help documentation: Use an expression to check the currently selected set of elements, and return true if at least one element matches the given expression.

Of course we know that the above statement is correct. But we can also write like this
alert($("input:checkbox").is(":checked")); //In this way We can judge whether a certain checkbox is selected. And so on. We can use: checked. Can we also use other ones? Of course it is possible. Search the help document for ":". All the types here can be used. Make a judgment

For example, $("input[name=btnClick]").is(":button"); is used to judge whether the control is a button, etc..

The rest is Everyone's own efforts...
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