看看官方的解释: You should not use the write or writeln methods on the current document after the document has finished loading unless you first call the open method, which clears the current document's window and erases all variables
果然如此...! 初玩JavaScript 见笑了 还望以后大家多多指点!
should not use the write or writeln methods on the current document after the document has finished loading
呵呵 我又对代码优化了一次 原代码使用了循环输出文字 这样的效率很明显的降低了 所以我把循环去掉了o(∩_∩)o...<head> <title>JavaScript Test</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <style> body{background:#000000; color:#FFFFFF; font-family:Georgia;} </style> <script language="javascript" type="text/javascript"> <!-- var str="Http://wWw.Csdn.Net"; var color="red"; speed=100; var i=0; var outstr=""; document.write("<div id=main align=center></div>"); function doit() { setInterval("redit()",speed) } function redit() { outstr=str.substring(0,i); outstr+=str.charAt(i).fontcolor(color); outstr+=(str.substring(i+1,str.length)); main.innerHTML=outstr; outstr=""; (i < str.length)?i++:i=0; } --> </script> </head> <body onLoad="doit()"> </body>
初玩JavaScript 见笑了 还望以后大家多多指点!
原代码使用了循环输出文字 这样的效率很明显的降低了
所以我把循环去掉了o(∩_∩)o...<head>
<title>JavaScript Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
body{background:#000000; color:#FFFFFF; font-family:Georgia;}
</style>
<script language="javascript" type="text/javascript">
<!--
var str="Http://wWw.Csdn.Net";
var color="red";
speed=100;
var i=0;
var outstr="";
document.write("<div id=main align=center></div>");
function doit()
{
setInterval("redit()",speed)
}
function redit()
{
outstr=str.substring(0,i);
outstr+=str.charAt(i).fontcolor(color);
outstr+=(str.substring(i+1,str.length));
main.innerHTML=outstr;
outstr="";
(i < str.length)?i++:i=0;
}
-->
</script>
</head>
<body onLoad="doit()">
</body>