简体   繁体   English

选取文字以刷新时更改

[英]marquee text with change on refresh

I've been trying to get a javascript code for random text on refresh to work with the classic html marquee tag, is there a way of doing this? 我一直在尝试获取刷新时的随机文本的javascript代码,以与经典的html marquee标记一起使用,有没有办法做到这一点? Putting it above the div gives me a whole moving paragraph but I want the text to scroll across the screen in sentence form, which only worked on the first sentence, then stopped working when on the others. 将其放在div上方可为我提供一个完整的移动段落,但我希望文本以句子形式在屏幕上滚动,该样式仅适用于第一个句子,然后停止使用其他句子。 Where can I insert this code so it will work? 我在哪里可以插入此代码,使其可以工作? Thanks 谢谢

<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>

It will work need to clean up the code like 它将需要清理像这样的代码

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>';

your full code can be 您的完整代码可以是

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM