【发布时间】:2011-12-15 01:20:10
【问题描述】:
需要在window.load中存储一些数据并在document.ready中检索:
<script>
$(window).load(function() { // Store here
$('img.storable').each(function() {
$(this).data("key", "value");
console.log($(this).data("key")); // Output: value
};
};
$(document).ready(function() { // Retrieve here
$('img.storable').each(function() {
console.log($(this).data("key")); // Output: undefined!
};
};
</script>
document.ready 中的输出未定义。我是否缺少有关 dom 事件的信息?
【问题讨论】:
标签: javascript jquery dom javascript-events