30、字符在按钮和状态栏上显示

30、字符在按钮和状态栏上显示

要完成此效果把如下代码加入到<body>区域中

 

<SCRIPT language="javascript">

 

var scroll = true;

var num = 0;

function scrollStatus() {

       

        var statusText = "";

        var statusChars = new Array( 't','y','p','h','o','o','n',' ','s','t','a','r','t');

        for (var l = 0; l < 1; l++) {

                for (var a = num; a < statusChars.length; a++)

                        statusText += statusChars[a];

                for (var b = 0; b < num; b++)

                        statusText += statusChars[b];

                }

        window.status = statusText;

        num++;

        if (num >= statusChars.length)

                num = 0;

        if (scroll) {

                setTimeout("scrollStatus()",100);

                }

        }

scrollStatus();

 

 

</SCRIPT>

<form name="form1">

<input name="stopIt" type="button" value="Stop Scrolling"

onClick="       if (scroll == false)

                        scroll = true;

                else

                        scroll = false;

                scrollStatus();

                scrollButton();

        ">

</form>

 

<SCRIPT language="javascript">

 

var num = 0;

scrollButton();

 

function scrollButton() {

        var buttonChars = new Array('S', 't', 'o', 'p', ' ', 'S', 'c', 'r', 'o', 'l', 'l', 'i',

 

'n', 'g', ' ', ' ');

        var buttonText = "";

        for (var a = num; a < buttonChars.length; a++)

                buttonText += buttonChars[a];

        for (var b = 0; b < num; b++)

                buttonText += buttonChars[b];

        num++;

        if (num >= buttonChars.length)

                num = 0;

        document.form1.stopIt.value = buttonText;

        if (scroll) {

                setTimeout("scrollButton();", 100);

                }

        }

 

</SCRIPT>

 

Write a comment

Comments: 0