问题描述
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type"content="text/html;charset=gb2312"/><title>第2章实例</title><metaname="Generate"content=“EditPlus”><metaname="Auther"content=""><metaname="Keywords"content=""><metaname="Description"content=""><scriptlanguage="javascript">my_str="javascript教程"for(i=0;i<my_length;i++){if(i%5==0){document.write("<br>");}document.write(my_str.charAt(i));}</script></head><body></body></html>
解决方案
解决方案二:
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type"content="text/html;charset=gb2312"/><title>第2章实例</title><metaname="Generate"content=“EditPlus”><metaname="Auther"content=""><metaname="Keywords"content=""><metaname="Description"content=""><scriptlanguage="javascript">my_str="javascript教程"for(i=0;i<my_length;i++){//这里的i<my_length写错了哈,应该是my_str.lengthif(i%5==0){document.write("<br>");}document.write(my_str.charAt(i));}</script></head><body></body></html>
解决方案三:
<scriptlanguage="javascript">my_str="javascript教程"for(i=0;i<my_length;i++){//这里的i<my_length写错了哈,应该是my_str.lengthif(i%5==0){document.write("<br>");}document.write(my_str.charAt(i));}</script>把这一段JS代码放到<body>标签里
解决方案四:
1。写错了。2。你document.write没要输出到可显示的地方<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type"content="text/html;charset=gb2312"/><title>第2章实例</title><metaname="Generate"content=“EditPlus”><metaname="Auther"content=""><metaname="Keywords"content=""><metaname="Description"content=""></head><body><scriptlanguage="javascript">my_str="javascript教程";for(i=0;i<my_str.length;i++){if(i%5==0){document.write("<br>");}document.write(my_str.charAt(i));}</script></body></html>
解决方案五:
楼上2位说的都不对哈,html页面是自上而下执行的,document.write肯定会指定,没有什么要放到<body>标签里
解决方案六:
如果不行,js部分换成这个:<scriptlanguage="javascript">varmy_str="javascript教程";for(i=0;i<my_str.length;i++){if(i%5==0){document.write("<br>");}document.write(my_str.charAt(i));}</script>