jquery无法正确呈现新行字符

时间:2012-02-16 13:13:22

标签: jquery

我一个接一个地在图像上显示文字。因此每行都有<BR>标签,但是当使用jquery在图像上显示文本时,BR未正确翻译,而页面顶部则出现空白空间。 这是我的剧本

<div id="HeaderMessage" class="HeaderMsg1">
<span class="HeaderMsg">A LIFETIME WARRANTY FOR EVERY PART WE REMANUFACTURE.<br/>We reengineer the faults out of parts so they won't fail again. Guaranteed.</span>
<span class="HeaderMsg">PROFIT FROM ENGINEERING EXPERTISE.<br/>We offer you reliable parts, low prices and easy access to automotive knowledge.</span>
<span class="HeaderMsg">JOIN US FOR A CAREER THAT CAN TAKE YOU FURTHER, FASTER. <br/>Reengineer your future with a world leader in the remanufacture of electronic automotive parts.</span>
<span class="HeaderMsg">THE SENSIBLE CHOICE IS THE GREENER CHOICE TOO.<br/>Our parts save precious raw materials, reduce automotive waste and require less CO2 to produce. </span>
</div>

$('.HeaderMsg1 span:gt(0)').hide();
    setInterval(function () {
    $('.HeaderMsg1 :first-child').fadeOut()
    .next('span').fadeIn()
    .end().appendTo('.HeaderMsg1');
 }, 5000);

在图像上显示文字后,我无法显示带文字的新行。 请帮我。感谢

1 个答案:

答案 0 :(得分:0)

您的选择器存在问题。

首先,.HeaderMsg1 :first-child(实际上是.HeaderMsg1 *:first-child,与.HeaderMsg1:first-child不同)转换为:

查找.HeaderMsg1,然后获取位于其下的任何元素,它也是来自其父级的first-child(可以是任何父级)。这将导致所有spanbr元素,这会导致在第一个时间间隔附加所有br

我相信你真正追求的是'.HeaderMsg1 span:first-child'(或类似的东西),它可以给你效果。

例如: http://jsfiddle.net/49kvB/