欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jQuery中is()方法用法實例

 更新時間:2015年01月06日 14:43:05   投稿:shichen2014  
這篇文章主要介紹了jQuery中is()方法用法,實例分析了is()方法的功能、定義及檢查匹配元素集合時的各種使用技巧,需要的朋友可以參考下

本文實例講述了jQuery中is()方法用法。分享給大家供大家參考。具體分析如下:

此方法使用參數(shù)來檢查匹配元素集合。
如果其中至少有一個元素符合這個給定的參數(shù)就返回true,否則返回false。

語法結(jié)構(gòu)一:

復(fù)制代碼 代碼如下:
$(selector).is(expr)

參數(shù)列表:
參數(shù) 描述
expr 字符串值,供匹配當(dāng)前元素集合的選擇器表達式。

實例代碼:

復(fù)制代碼 代碼如下:

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8"/>
<meta name="author" content="http://www.dbjr.com.cn/" />
<title>is()函數(shù)-腳本之家</title>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  alert($("li").parent().is("ul"))
})
</script>
</head>
<body>
<div>
  <ul>
    <li>div+css專區(qū)</li>
    <li>jQuery專區(qū)</li>
  </ul>
</div>
</body>
</html>

下面代碼檢測li元素的父元素是否是ul,如果是返回true,否則返回false。

語法結(jié)構(gòu)二:

參數(shù)列表:

參數(shù) 描述
element 用于匹配元素的DOM元素或者jQuery元素。

實例代碼:

實例一:

復(fù)制代碼 代碼如下:

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8"/>
<meta name="author" content="http://www.dbjr.com.cn/" />
<title>is()函數(shù)-腳本之家</title>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  alert($("li").parent().is(document.getElementById("parent")))
})
</script>
</head>
<body>
<div>
  <ul id="parent">
    <li>div+css專區(qū)</li>
    <li>jQuery專區(qū)</li>
  </ul>
</div>
</body>
</html>

實例二:

復(fù)制代碼 代碼如下:

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8"/>
<meta name="author" content="http://www.dbjr.com.cn/" />
<title>is()函數(shù)-腳本之家</title>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  alert($("li").parent().is($("#parent")))
})
</script>
</head>
<body>
<div>
  <ul id="parent">
    <li>div+css專區(qū)</li>
    <li>jQuery專區(qū)</li>
  </ul>
</div>
</body>
</html>

語法結(jié)構(gòu)三:

使用函數(shù)用來遍歷元素的集合。
此函數(shù)接受一個參數(shù)index,這是元素在jQuery集合的索引。函數(shù)中, this指的是當(dāng)前的DOM元素。

參數(shù)列表:

參數(shù) 描述
function(index) 定義返回is()匹配值的函數(shù)。
index為當(dāng)前元素在匹配元素集合中的索引值。

實例代碼:

復(fù)制代碼 代碼如下:

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8"/>
<meta name="author" content="http://www.dbjr.com.cn/" />
<title>is()函數(shù)-腳本之家</title>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  alert($("li").parent().is(function(index){return $("ul").attr("id")=="parent"}))
})
</script>
</head>
<body>
<div>
  <ul id="parent">
    <li>div+css專區(qū)</li>
    <li>jQuery專區(qū)</li>
  </ul>
</div>
</body>
</html>

希望本文所述對大家的jQuery程序設(shè)計有所幫助。

相關(guān)文章

最新評論