我想使标题文本可滚动,我使下面的代码滚动得很好,但我输入的文本显示没有空格,意味着不考虑字符串中的空格.
<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 "));