jQuery 附加文本 [英] jQuery append text
问题描述
我想在 div 中附加一些简单的数据,例如:
$('#msg').append('Some text');
在正文中,我想我需要像这样放置 html.
<div id="msg"></div>//显示里面的文字.
但是,我想向 #msg
添加一些 CSS.例如,背景颜色.现在的问题是,由于 #msg
div 一直存在,即使没有附加文本,我也会看到背景颜色.我试图添加像display:none"这样的 css,但在这种情况下,我看不到附加的文本.我可以这样做,以便 #msg
div 仅在文本附加到 #test
中时才出现在 #test
中吗?谢谢.
$('#msg').append('Some text').show();
I want to append some simple data in a div like:
$('#msg').append('Some text');
In the body, i think i will need to place the the html like.
<div id="test">
<div id="msg"></div> //show text inside it.
</div>
However, I want to add some CSS to the #msg
. For example, background color. Now the problem is that, since the #msg
div is present all the time, i see the background color even when the text is not appended to it. I have tried to add css like "display:none, but in that case i can not see the text appended to it.
Can i do it so that the #msg
div appears inside the #test
only when the text is appended to it? Thanks.
$('#msg').append('Some text').show();
这篇关于jQuery 附加文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!