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

jQuery的context屬性用法實(shí)例

 更新時(shí)間:2014年12月27日 12:10:29   投稿:shichen2014  
這篇文章主要介紹了jQuery的context屬性用法,實(shí)例分析了context屬性返回節(jié)點(diǎn)內(nèi)容的使用技巧,具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了jQuery的context屬性用法。分享給大家供大家參考。具體分析如下:

此屬性可以返回傳給jQuery()的原始DOM節(jié)點(diǎn)內(nèi)容,即jQuery()方法的第二個(gè)參數(shù)值。
如果jQuery()方法沒有指定此參數(shù),那么context指向當(dāng)前文檔(document)。
語法結(jié)構(gòu):

復(fù)制代碼 代碼如下:
$("selector").context

實(shí)例代碼:

實(shí)例一:

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

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.dbjr.com.cn/" />
<title>腳本之家</title>
<style type="text/css">
div
{
  width:150px;
  height:150px;
  border:1px solid blue;
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript"> 
$(document).ready(function(){
  $("button").click(function(){
    alert($("li").context);
  })
})
</script> 
</head>
<body>
<div>
  <ul>
    <li>測試腳本</li>
  </ul>
</div>
<button>點(diǎn)擊測試</button>
</body>
</html>

默認(rèn)狀態(tài)下,傳給jQuery()的原始DOM節(jié)點(diǎn)是Document,在IE瀏覽器下會(huì)返回[object],其他瀏覽器返回[object HTMLDocument]。
實(shí)例二:

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

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.dbjr.com.cn/" />
<title>腳本之家</title>
<style type="text/css">
div
{
  width:150px;
  height:150px;
  border:1px solid blue;
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript"> 
$(document).ready(function(){
  $("button").click(function(){
    alert($("li",document.getElementById("myid")).context);
  })
})
</script>
</head>
<body>
<div>
  <ul id="myid">
    <li>測試腳本</li>
  </ul>
</div>
<button>點(diǎn)擊測試</button>
</body>
</html>

上述代碼返回值是[object HTMLUListElement],但是在IE瀏覽器是[object]

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

相關(guān)文章

  • jQuery、zepto、js常用小技巧

    jQuery、zepto、js常用小技巧

    本文給大家分享的是小編jQuery、zepto、js常用小技巧的心得,非常實(shí)用,有需要的小伙伴可以參考下
    2017-02-02
  • jQuery 動(dòng)畫與停止動(dòng)畫效果實(shí)例詳解

    jQuery 動(dòng)畫與停止動(dòng)畫效果實(shí)例詳解

    這篇文章主要介紹了jQuery 動(dòng)畫與停止動(dòng)畫效果,結(jié)合實(shí)例形式詳細(xì)分析了jQuery 動(dòng)畫與停止動(dòng)畫效果相關(guān)函數(shù)功能、用法及使用注意事項(xiàng),需要的朋友可以參考下
    2020-05-05
  • jQuery調(diào)用Webservice傳遞json數(shù)組的方法

    jQuery調(diào)用Webservice傳遞json數(shù)組的方法

    這篇文章主要介紹了jQuery調(diào)用Webservice傳遞json數(shù)組的方法,實(shí)例分析了jQuery基于ajax與Webservice傳遞json數(shù)據(jù)的相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2016-08-08
  • jquery 多行滾動(dòng)代碼(附詳細(xì)解釋)

    jquery 多行滾動(dòng)代碼(附詳細(xì)解釋)

    在網(wǎng)上可以隨處找到這段代碼,但是沒有任何人解釋這段代碼,只要自己研究好久。
    2010-06-06
  • 最新評(píng)論