我一直试图在刷新时获取随机文本的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>
答案 0 :(得分:0)
它需要清理像
这样的代码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>