我想使标题文本可以滚动,使下面的代码可以滚动,但是我输入的文本没有空格显示,这意味着不考虑字符串中的空格。

<script type="text/javascript">
    //function for tittle scrolling
    function scrlsts() {
        //var scrltest = " Nature ";
        scrltest=document.title;

        //alert(scrltest);
        scrltest = scrltest.substring(1, scrltest.length) + scrltest.substring(0, 1);

        //alert(scrltest);
        document.title = scrltest;

        setTimeout("scrlsts()", 1000);
    }
    $(document).ready(function() {
        var scrltest = " Nature dff ssfd ";
        document.title=scrltest;
        scrlsts();
    });
</script>

提前致谢

最佳答案

很久没做这些了,but this should work:

(function titleScroller(text) {
    document.title = text;
    setTimeout(function () {
        titleScroller(text.substr(1) + text.substr(0, 1));
    }, 500);
}(" Nature dff ssfd "));

09-17 02:12