HTML5 custom Data properties, that is, data-* custom properties.
For example
<div data-last-value= "data-hidden=" true "data-options= ' {" name ":" John "} ' ></div>
There are three ways to access and modify data:
1. Use the GetAttribute SetAttribute method such as Div.getattribute ("Data-last-value")
2. Using the DataSet property
Returns a collection
Div.dataset-Domstringmap {options: "{\" name\ ": \" john\ "}", Hidden: "True", Lastvalue: "43"}
can access, add, delete
Div.dataset.hidden div.dataset.newAttr = "123" Delete Div.dataset.hidden
3. Using the data method of jquery
. Data (key, value)
. Data (key, value)
. Data (obj)--Set multiple key-value pairs
. Data (Key)
. Data (Key)
. Data ()-Returns a collection
jquery is very special, it will automatically convert the return value string to the corresponding data type.
such as the $ ("div") above. Data ()--+ options: {"name": "John"}, Hidden:true, lastvalue:43}
Note:For the DataSet property and the data method of jquery: The Data-property name if it contains a hyphen, for example: Data-last-value, the hyphen is stripped and converted to a camel-named name, the preceding property name is converted to: Lastvalue.