代码运行后顶部会出现一堆undefined,和我定义的数组boxValue.length相同。求解。。
这是代码:<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"><script type="text/javascript">function getEachLine()
{
for(line = 0; line < boxValue[row].length; line++)
{
document.write("<td>"+boxValue[row][line]+"</td>");
}
}function makeTable()
{
document.write("<table><tr><th>字符类</th><th>匹配的字符</th><th>示例</th></tr>");
for (row = 0; row < boxValue.length; row++)
{
document.write("<tr>"+ getEachLine() +"</tr>");
}
document.write("</table>");
}</script></head>
<body><script type="text/javascript">var boxValue = new Array();
boxValue[0] = new Array();
boxValue[0][0] = "\\d";
boxValue[0][1] = "0~9的任何数字";
boxValue[0][2] = "\\d\\d将匹配72,但不匹配 aa 或者 7a";boxValue[1] = new Array();
boxValue[1][0] = "\\D";
boxValue[1][1] = "任何非数字字符";
boxValue[1][2] = "\\D\\D\\D将匹配 abc,但不匹配 123 或者 8ef";boxValue[2] = new Array();
boxValue[2][0] = "\\w";
boxValue[2][1] = "任何单词字符,即 A~Z、a~z、0~9之间的字符,以及下划线(_)字符";
boxValue[2][2] = "\\w\\w\\w\\w将匹配Ab_2,但普匹配 $@%* 或者 Ab_@";boxValue[3] = new Array();
boxValue[3][0] = "\\W";
boxValue[3][1] = "任何非单词字符";
boxValue[3][2] = "\\W将匹配 @,但不匹配 a";boxValue[4] = new Array();
boxValue[4][0] = "\\s";
boxValue[4][1] = "任何空白字符,包含水平制表符、换行符、回车符、走纸符以及垂直制表符";
boxValue[4][2] = "\\s将与制表符 tab 匹配";boxValue[5] = new Array();
boxValue[5][0] = "\\S";
boxValue[5][1] = "任何非空白字符";
boxValue[5][2] = "\\S将匹配 A, 但不匹配制表符 tab";boxValue[6] = new Array();
boxValue[6][0] = ".";
boxValue[6][1] = "除了换行符\"\\n\"之外的任何单个字符";
boxValue[6][2] = ". 将匹配 a 或者 4,或者 @";boxValue[7] = new Array();
boxValue[7][0] = "[...]";
boxValue[7][1] = "匹配位于方括号之内的任何一个字符";
boxValue[7][2] = "[abc]将匹配a、b或者c,但不匹配任何其他字符;<br />[a-z]将匹配在a~z范围内的任何字符";boxValue[8] = new Array();
boxValue[8][0] = "[^...]";
boxValue[8][1] = "匹配除了方括号之内字符之外的任何字符";
boxValue[8][2] = "[^abc]将匹配除了a、b或者c之外的任何字符;<br />[^a-z]将匹配除了a~z范围之外的任何字符";
makeTable();//下面的代码是用来测试的
document.write("<br />");
document.write(boxValue.length);
document.write("<br />");
document.write(boxValue[1].length);
</script></body>
</html>

解决方案 »

  1.   

    function getEachLine()
    {
    for(line = 0; line < boxValue[row].length; line++)
    {
    document.write("<td>"+boxValue[row][line]+"</td>");
    }
    }function makeTable()
    {
    document.write("<table><tr><th>字符类</th><th>匹配的字符</th><th>示例</th></tr>");
    for (row = 0; row < boxValue.length; row++)
    {
    document.write("<tr>"+ getEachLine() +"</tr>"); 
    }
    document.write("</table>");
    }问题出现在 getEachLine() 这个方法的结果是输出     makeTable()这个函数还是 输出 没有返回结果 
    getEachLine() 不要输出 返回字符串 就行 
      

  2.   

    function getEachLine() {
    for (line = 0; line < boxValue[row].length; line++) {
    document.write("<td>" + boxValue[row][line] + "</td>");
    }
        return ""; //加上这个就行
    }
      

  3.   

    document.write 这个方式最好不要用,换用innerText/innerHTML等方式进行赋值。
      

  4.   

    哦~~我明白了~~从两位的回答来看,我的写法确实有问题,就像在document里又写了document一样。后来我改成这样了:function getEachLine()
    {
    var eachLine="";
    for(line = 0; line < boxValue[row].length; line++)
    {
    eachLine = eachLine + "<td>"+boxValue[row][line]+"</td>";
    }
    return eachLine;
    }