题目:要求把1到100之间能被3整除的数显示出来,要求以表格显示,每行显示8个数字。程序写出来了,每行显示8个做不出来求解答<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
table{ border:1px #0000FF solid; border-collapse:collapse;}
td{ border:1px #0000ff solid; width:50px; text-align:center}
</style>
</head><body>
<table>
<tr><script language="javascript">
for(i=1;i<=100;i++)
{
if(i%3==0)
document.write("<td>"+i+"</td>")
}
</script></tr>
</table>
</body>
</html>

解决方案 »

  1.   


    var k=0;
    for(i=1;i<=100;i++)
    {
    if(i%3==0){
    k++;document.write("<td>"+i+"</td>")
    if(k%8==0){
    document.write("</tr><tr>")
    }
    }
    }
      

  2.   

    var j=0;
    for(i=1;i<=100;i++)
    {
    if(i%3==0){
    j++;
    document.write("<td>"+i+"</td>")
    if(j%8==0)document.write("</tr><tr>")
    }
    }
      

  3.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <style type="text/css">
    table{ border:1px #0000FF solid; border-collapse:collapse;}
    td{ border:1px #0000ff solid; width:50px; text-align:center}
    </style>
    </head><body>
    <table>
    <script language="javascript">
    var count=0;
    document.write("<tr>");
    for(i=1;i<=100;i++)
    {
    if(i%3==0){
    document.write("<td>"+i+"</td>");
    count++;
    }
    if(count%8==0){
    document.write("</tr><tr>");
    }
    }
    </script>
    </table>
    </body>
    </html>
      

  4.   

    <script language="javascript">
    for(i=1;i<=100;i++)
    {
    if(i%3==0&&i%8==0){
    document.write("<tr>")
    }
    if(i%3==0){
    document.write("<td>"+i+"</td>")
    }
    if(i%3==0&&i%8==0){
    document.write("</tr>")
    }
    }
    </script>
    楼主的问题似乎是这样的,但是没有你想想的那么好,这点我也不太熟悉,不过大概就是这个意思,不足的地方,大家一起改正下,我只会做到这么点。
      

  5.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <style type="text/css">
    table{ border:1px #0000FF solid; border-collapse:collapse;}
    td{ border:1px #0000ff solid; width:50px; text-align:center}
    </style>
    </head><body>
    <table>
    <tr><script language="javascript">
    for(i=3;i<100;i+=3)
    {document.write("<td>"+i+"</td>");
    if(i%24==0){
    document.write("<tr></tr>");
    }
    }
    </script></tr>
    </table>
    </body>
    </html>