需要一些數據存儲在window.load
和檢索document.ready
:在window.load和document.ready中的jQuery數據(),有沒有定義?
<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事件的一些事情?