最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jQuery.data()

Contents:

jQuery.data( element, key, value ) 返回: jQuery

描述: 在匹配遠(yuǎn)上綁定任意相關(guān)數(shù)據(jù)。

  • version added: 1.2.3jQuery.data( element, key, value )

    element要關(guān)聯(lián)數(shù)據(jù)的DOM對象

    key存儲的數(shù)據(jù)名

    value新數(shù)據(jù)值

注意這是一個底層的方法,你應(yīng)該用.data()代替。

jQuery.data() 方法允許我們在DOM元素上附加任意類型的數(shù)據(jù),避免了循環(huán)引用的內(nèi)存泄漏風(fēng)險(xiǎn)。 jQuery ensures that the data is removed when DOM elements are removed via jQuery methods, and when the user leaves the page. 我們可以在一個元素上設(shè)置不同的值,并獲取這些值:

jQuery.data(document.body, 'foo', 52);
		jQuery.data(document.body, 'bar', 'test');

注意:

  • 注意這個方法目前并不提供在XML文檔上跨平臺設(shè)置,作為Internet Explorer不允許通過自定義屬性附加數(shù)據(jù)。

例子:

Store then retrieve a value from the div element.

<!DOCTYPE html>
<html>
<head>
  <style>
  div { color:blue; }
  span { color:red; }
  </style>
  <script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
  <div>
    The values stored were 
    <span></span>
    and
    <span></span>
  </div>
<script>var div = $("div")[0];
    jQuery.data(div, "test", { first: 16, last: "pizza!" });
    $("span:first").text(jQuery.data(div, "test").first);
    $("span:last").text(jQuery.data(div, "test").last);</script>

</body>
</html>

Demo:

jQuery.data( element, key ) 返回: Object

描述: 返回元素上儲存的相應(yīng)名字的數(shù)據(jù),可以用data(name, value)來設(shè)定。

  • version added: 1.2.3jQuery.data( element, key )

    element要關(guān)聯(lián)數(shù)據(jù)的DOM對象

    key存儲的數(shù)據(jù)名

  • version added: 1.4jQuery.data( element )

    element要關(guān)聯(lián)數(shù)據(jù)的DOM對象

注意這是一個底層的方法,你應(yīng)該用.data()代替。

.data()方法允許我們在DOM元素上附加任意類型的數(shù)據(jù),避免了循環(huán)引用的內(nèi)存泄漏風(fēng)險(xiǎn)。我們可以在一個元素上設(shè)置不同的值,并獲取這些值:

alert(jQuery.data( document.body, 'foo' ));
alert(jQuery.data( document.body ));

上面幾行代碼alert body元素上設(shè)置的值。若果沒有設(shè)置任何值,那么將返回null。

調(diào)用沒有參數(shù)的jQuery.data(element)時將獲取一個作為JavaScript對象的所有值。jQuery內(nèi)部自身使用這個方法來綁定數(shù)據(jù),如事件處理器,所以不要以為這只包含數(shù)據(jù)儲存你的代碼。

HTML 5 data- 屬性

直jQuery 1.4.3起, HTML 5 data- 屬性 將自動被引用到j(luò)Query的數(shù)據(jù)對象中。

舉個例子, 給定下面的HTML:

<div data-role="page" data-hidden="true" data-options='{"name":"John"}'></div>

All of the following jQuery code will work.

$("div").data("role") === "page";
$("div").data("hidden") === true;
$("div").data("options").name === "John";

Note that strings are left intact while JavaScript values are converted to their associated value (this includes booleans, numbers, objects, arrays, and null). The data- attributes are pulled in the first time the data property is accessed and then are no longer accessed or mutated (all data values are then stored internally in jQuery).

注意:

  • 注意這個方法目前并不提供在XML文檔上跨平臺設(shè)置,作為Internet Explorer不允許通過自定義屬性附加數(shù)據(jù)。

例子:

Get the data named "blah" stored at for an element.

<!DOCTYPE html>
<html>
<head>
  <style>
div { margin:5px; background:yellow; }
button { margin:5px; font-size:14px; }
p { margin:5px; color:blue; }
span { color:red; }
  </style>
  <script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
  <div>A div</div>
<button>Get "blah" from the div</button>
<button>Set "blah" to "hello"</button>

<button>Set "blah" to 86</button>
<button>Remove "blah" from the div</button>
<p>The "blah" value of this div is <span>?</span></p>
<script>
$("button").click(function(e) {
  var value, div = $("div")[0];

  switch ($("button").index(this)) {
    case 0 :
      value = jQuery.data(div, "blah");
      break;
    case 1 :
      jQuery.data(div, "blah", "hello");
      value = "Stored!";
      break;
    case 2 :
      jQuery.data(div, "blah", 86);
      value = "Stored!";
      break;
    case 3 :
      jQuery.removeData(div, "blah");
      value = "Removed!";
      break;
  }

  $("span").text("" + value);
});

</script>

</body>
</html>

Demo:

jQuery 1.6 API 中文版腳本之家整理、修訂 (2011年6月)
潍坊市| 信宜市| 尼勒克县| 多伦县| 合山市| 吉安市| 利川市| 嘉荫县| 临颍县| 佛坪县| 龙口市| 东乡| 金湖县| 乐亭县| 江孜县| 务川| 台东市| 盐亭县| 辽宁省| 崇礼县| 宁夏| 忻城县| 河东区| 夏河县| 巴中市| 安塞县| 巩义市| 鄯善县| 延寿县| 荔浦县| 靖边县| 沅江市| 三亚市| 独山县| 永靖县| 沧源| 文水县| 鹤峰县| 宁武县| 海兴县| 五台县|