目录
当前位置: 首页 > 文档资料 > Snap.svg 英文文档 >

Element.data(key, [value])

优质
小牛编辑
131浏览
2023-12-01

Adds or retrieves given value associated with given key. (Don’t confuse with data- attributes)

See also Element.removeData

Parameters

  1. keystringkey to store data
  2. valueanyvalue to store

Returns: objectElement

or, if value is not specified:

Returns: any value

Usage

for (var i = 0, i < 5, i++) {
paper.circle(10 + 15 * i, 10, 10)
.attr({fill: "#000"})
.data("i", i)
.click(function () {
alert(this.data("i"));
});
}