我一直在尝试获取刷新时的随机文本的javascript代码,以与经典的html marquee标记一起使用,有没有办法做到这一点?将其放在div上方可为我提供一个完整的移动段落,但我希望文本以句子形式在屏幕上滚动,该样式仅适用于第一个句子,然后停止处理其他句子。我在哪里可以插入此代码,使其可以工作?谢谢
<div>
<script language="JavaScript" type="text/javascript">// <![CDATA[
// <![CDATA[
function random_imglink(){
var myimages=new Array()
//specify random images below. You can have as many as you wish
myimages[1]="<marquee behavior="scroll" direction="left">Text 1</marquee>"
myimages[2]="<marquee behavior="scroll" direction="left">Text 2</marquee>"
myimages[3]="<marquee behavior="scroll" direction="left">Text 3</marquee>"
var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<p>'+myimages[ry]+'</p>')
}
random_imglink()
// ]]]]><![CDATA[>
// ]]></script>
</div>
最佳答案
它将需要清理像这样的代码
myimages[1]='<marquee behavior="scroll" direction="left">Text 1</marquee>';
myimages[2]='<marquee behavior="scroll" direction="left">Text 2</marquee>';
myimages[3]='<marquee behavior="scroll" direction="left">Text 3</marquee>';
您的完整代码可以是
<div>
<script language="JavaScript" type="text/javascript">
function random_imglink(){
var myimages=new Array()
//specify random images below. You can have as many as you wish
myimages[1]='<marquee behavior="scroll" direction="left">Text 1</marquee>';
myimages[2]='<marquee behavior="scroll" direction="left">Text 2</marquee>';
myimages[3]='<marquee behavior="scroll" direction="left">Text 3</marquee>';
var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<p>'+myimages[ry]+'</p>')
}
random_imglink()
</script>
</div>