jQuery is() 方法

jQuery 教程 · 2019-03-28 07:38:45

实例

如果 <p> 的父元素是 <div> 元素,弹出提示信息:

if ($("p").parent().is("div")) {
    alert("p 的父元素是 div");
}

定义和使用

is() 方法用于查看选择的元素是否匹配选择器。

语法

$(selector).is(selectorElement,function(index,element))

参数 描述
selectorElement 必须。选择器表达式,根据选择器/元素/jQuery 对象检查匹配元素集合,如果存在至少一个匹配元素,则返回 true,否则返回 false
function(index,element)

可选。指定了选择元素组要执行的函数。

  • index - 元素的索引位置
  • element - 当前元素 ( "this" 选择器也可以使用 )

点击查看所有 jQuery 教程 文章: https://codercto.com/courses/l/35.html

查看所有标签

The Little Typer

The Little Typer

Daniel P. Friedman、David Thrane Christiansen、Duane Bibby、Robert Harper、Conor Mcbride / MIT Press / 2018-10-16 / GBP 30.00

An introduction to dependent types, demonstrating the most beautiful aspects, one step at a time. A program's type describes its behavior. Dependent types are a first-class part of a language, and are......一起来看看 《The Little Typer》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

URL 编码/解码
URL 编码/解码

URL 编码/解码

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具