jQuery 1.x
元素在需要时会收到一个唯一标识符(缓存键),存储在节点的ele[jQuery.expando]
属性set by this line of code中。 Mootools uses similar logic。jQuery 2.x如何唯一标识元素(在.data()中)
所以在jQuery 1.x
var test = document.createElement("span");
console.log(test[jQuery.expando]);//undefined
$(test).data("test", {stuff:2});
console.log(test[jQuery.expando]);//some uid
我很好奇,因为我在执行类似的逻辑,jQuery的识别2.x
节点的过程很。在github回购中引用一个行号会很好!
你能不能给我任何属性名的例子或他们定义的呢? – megawac
它在repo中的'data/Data.js'中定义,并且如果使用jquery数据检查dom节点的javascript表示形式,则它的属性看起来像'jquery1426525252650.115245662563'(构造函数是' jQuery.expando + Math.random()' – Entoarox
对不起,没有看到他们在https://github.com/jquery/jquery/blob/master/src/data/Data.js中的元素上定义了uid的位置你请链接 – megawac