开发者

jQuery doesn't return data

I set data with jQuery.data() but I couldn't get it later. Code:

jQuery('#test').live('click', function() {
    alert(jQuery.data($(this), 'key'));
});
var element = jQuery('<div id="test">Test<开发者_JAVA技巧;/div>');
jQuery.data(element, 'key', { test: "String" });
jQuery('body').append(element);

I'm using jQuery 1.5. Is this a bug (in jQuery .live()) or am I doing something wrong?


Try this instead:

$('#test').live('click', function() {
    alert($(this).data('key'));
});
var element = $('<div id="test">Test</div>');
$(element).data('key', { test: "String" });
$('body').append(element);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜