zoukankan      html  css  js  c++  java
  • jquery data()

    data()

    .data( key, value )

      Description: Store arbitrary data associated with the matched elements.

    • .data( key, value )
    • .data( obj )

    .data( key )

      Description: Return the value at the named data store for the first element in the jQuery collection, as set by data(name, value) or by an HTML5 data-* attribute.

    • .data( key )
    • .data()

    Example1

    $( "body" ).data( "foo", 52 ); 
    $( "body" ).data( "bar", { myType: "test", count: 40 } );
    $( "body" ).data( { baz: [ 1, 2, 3 ] } );
    $( "body" ).data( "foo" ); // 52
    $( "body" ).data();
    // { foo: 52, bar: { myType: "test", count: 40 }, baz: [ 1, 2, 3 ] }

    Example2

    HTML5 data-* Attributes

    <div data-role="page" data-last-value="43" data-hidden="true" data-options='{"name":"John"}'></div>
    
    $( "div" ).data( "role" ) === "page";
    $( "div" ).data( "lastValue" ) === 43;
    $( "div" ).data( "hidden" ) === true;
    $( "div" ).data( "options" ).name === "John";

    Additional:

    jQuery searches among the attributes of the element, converting a camel-cased string into a dashed string and then prepending data- to the result. So, the string lastValue is converted to data-last-value.

  • 相关阅读:
    iostream与iostream.h的区别
    [HAOI2011]向量
    [POI2011]Temperature
    [洛谷2839/国家集训队]middle
    [TJOI2013]松鼠聚会
    [HNOI2015]接水果
    [BZOJ3772]精神污染
    [BZOJ3251]树上三角形
    [ZJOI2011]道馆之战
    [SDOI2013]森林
  • 原文地址:https://www.cnblogs.com/hzj680539/p/5031327.html
Copyright © 2011-2022 走看看