如何“刷新"用jQuery添加新LI后的UL? [英] how to "refresh" UL after adding new LI with jQuery?
问题描述
我认为它类似于这个问题,但是我的问题是关于jQuery和HTML5的.我在<UL>
中添加了<LI>
元素,并在豌豆内部添加了链接(<a href="..">
)作为纯文本,不可单击.除此之外,在适当添加<img src="..">
元素时,图像不可见.
I think it's similar to this question, but my problem is about jQuery and HTML5. I'm adding a <LI>
element to <UL>
and links (<a href="..">
) added inside apears as plain text, not clickable. Besides that, images are not visible, while <img src="..">
elements are being added propertly.
在使用append()
之后,看起来我需要一些刷新"技巧.哪一个?
Looks like I need some "refresh" trick to do after using append()
. Which one?
这是我的代码,以防万一:
This is my code, just in case:
$('ul').append($('<li/>').append($('<img/>').attr('src', 'http://example.com')));
在正确构建HTML时,图像不可见.我正在Mac上的Safari 5.1中尝试.
The image is not visible, while HTML is being build correctly. I'm trying in Safari 5.1 on Mac.
顺便说一句,在Firefox 10.0中一切正常.也许实际的问题是我在Safari中使用XML + XSL格式,在Firefox中使用纯HTML5.
BTW, everything works perfectly fine in Firefox 10.0. Maybe the actual problem is that I'm using XML+XSL formatting in Safari and plain HTML5 in Firefox..
推荐答案
这是它的工作方式(另请参见此问题 ):
This is how it works instead (see this question also):
$('#list').html('<li>foo</li>');
这篇关于如何“刷新"用jQuery添加新LI后的UL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!