ホームページ  >  記事  >  ウェブフロントエンド  >  jQuery_jqueryでのis()メソッドの使用例

jQuery_jqueryでのis()メソッドの使用例

WBOY
WBOYオリジナル
2016-05-16 16:21:531040ブラウズ

この記事の例では、jQuery での is() メソッドの使用法について説明します。皆さんの参考に共有してください。具体的な分析は次のとおりです。

このメソッドはパラメーターを使用して、一致する要素のコレクションをチェックします。
少なくとも 1 つの要素が指定されたパラメーターに一致する場合は true を返し、それ以外の場合は false を返します。

文法構造 1:

コードをコピーします コードは次のとおりです:
$(selector).is(expr)

パラメータリスト:
参数 描述
expr 字符串值,供匹配当前元素集合的选择器表达式。

コード例:

コードをコピーします コードは次のとおりです:



<頭>

is() 関数 - スクリプト ホーム

<スクリプトタイプ="text/javascript">
$(document).ready(function(){
アラート($("li").parent().is("ul"))
})





  • div CSS エリア

  • jQuery ゾーン






次のコードは、li 要素の親要素が ul であるかどうかを検出し、ul である場合は true を返し、そうでない場合は false を返します。

文法構造 2:

パラメータリスト:

コード例:

例 1:

コードをコピーします コードは次のとおりです:



<頭>

is() 関数 - スクリプト ホーム

<スクリプトタイプ="text/javascript">
$(document).ready(function(){
alert($("li").parent().is(document.getElementById("parent")))
})





  • div CSS エリア

  • jQuery ゾーン






例 2:

コードをコピーします コードは次のとおりです:


<頭>

is() 関数 - スクリプト ホーム

<スクリプトタイプ="text/javascript">
$(document).ready(function(){
アラート($("li").parent().is($("#parent")))
})





  • div CSS エリア

  • jQuery ゾーン






Grammar structure three:

Use functions to iterate over a collection of elements.
This function accepts a parameter index, which is the index of the element in the jQuery collection. In the function, this refers to the current DOM element.

Parameter list:

参数 描述
function(index) 定义返回is()匹配值的函数。
index为当前元素在匹配元素集合中的索引值。

Example code:

Copy code The code is as follows:






is() function-Script Home






  • div css area

  • jQuery Zone





I hope this article will be helpful to everyone’s jQuery programming.

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。