Javascript 更改jQuery字幕文本和css/样式
我有divJavascript 更改jQuery字幕文本和css/样式,javascript,jquery,css,marquee,Javascript,Jquery,Css,Marquee,我有div <div id="rotatingText" class="marquee"> </div> 现在我需要在成功后在ajax上更改该div的文本和css。我在ajax响应中获得了新的文本和css属性。通过该文本和css,我调用以下内容: function setRotatingTextProperties( value, css, objectId ) { var object = document.getElementById( objectId )
<div id="rotatingText" class="marquee">
</div>
现在我需要在成功后在ajax上更改该div的文本和css。我在ajax响应中获得了新的文本和css属性。通过该文本和css,我调用以下内容:
function setRotatingTextProperties( value, css, objectId )
{
var object = document.getElementById( objectId );
object.innerHTML = value;
jQuery ( object ).attr( 'style', css );
}
在那个帐篷停止工作之后。
我认为jQuery marquee在该div中设置了一些样式,我用以下内容覆盖它:
jQuery ( object ).attr( 'style', css );
如果我只是将css添加到现有的
var currentCss = jQuery ( object ).attr( 'style');
jQuery ( object ).attr( 'style', currentCss + css );
经过多次修改,我最终将得到大量不可用的css。而且css将定期(每五秒钟)更改。。。
任何建议和想法都将不胜感激。
Thx提前。事实上,我认为您的问题不在于css,而在于:
jQuery ( object ).attr( 'style', css );
根据我的经验,jquerymarquee的问题在于文本的变化。所以你的问题是:
object.innerHTML = value;
最好的解决方案(如果您可以更改该页面的html)是将span添加到其中:
<div id="rotatingText" class="marquee">
<span id="rotatingTextSpan"></span>
</div>
如果由于任何原因无法更改该页面的HTML,则始终可以在window.load或document.ready中将span值插入该页面,但在使用以下内容初始化字幕之前
$( '#predefineImageRotatingTextSpan' ).html( '<span id="predefineImageRotatingTextSpan"></span>' );
$('#预定义图像旋转文本span').html('';
然后使用上述函数
编辑:
如果开始时div中有一些预定义的文本,只需将其值复制到该div中即可:
var $object = $( '#predefineImageRotatingTextSpan' )
var initialText = $object.text()
$object.html( '<span id="predefineImageRotatingTextSpan"> ' + initialText + '</span>' );
var$object=$(“#预定义图像旋转文本span”)
var initialText=$object.text()
$object.html(“”+initialText+“”);
是的,你是对的,谢谢你的时间,还有详尽的答案
$( '#predefineImageRotatingTextSpan' ).html( '<span id="predefineImageRotatingTextSpan"></span>' );
var $object = $( '#predefineImageRotatingTextSpan' )
var initialText = $object.text()
$object.html( '<span id="predefineImageRotatingTextSpan"> ' + initialText + '</span>' );