【发布时间】:2015-06-05 20:29:16
【问题描述】:
我无法弄清楚为什么我的页面无法正常工作。当我尝试加载它时,它只会给我一个白屏。有没有我遗漏的代码?我也不知道我的空间是否重要。这是我的代码:
<!DOCTYPE html>
<html>
<head><body>
<title>Initializing an Array</title>
<style type="text/css">
table {width:10em}
th {text-align:left}
</style>
<script language="JavaScript">
<!--
{//create (declare) two new arrays
var n1=new Array(5); //allocate five-element Array
var n2=new Array (); //allocate empty Array
//assign values to each element of Array n1
for ( var i = 0; i <n1.length; ++i )
n1[ i ] = i;
//create and initialize five elements in Array n2
for ( i=0; i <5; ++i )
n2[ i ] = i;
outputArray("Array n1:",n1);
outputArray("Array n2:",n2);
//output the heading followed by a two-column table
//containing subscripts and elements of "theArray"
function outputArray (heading,theArray)}
{
document.writeln("<h2>"+heading+"</h2>");
document.writeln("table border=\"1\"");
document.writeln("<thead><th>Subscripts</th>"+"<th>Value</th></thead> <tbody>");
//output the subscript and value of each array element
for ( var i = 0; i <theArray.length; i++ )
document.writeln("<tr><td>+i+"</td><td>"+theArray[i]+"</td></tr>");
document.writeln("/tbody></table>");
} //end function outputArray
//-->
</script>
</head></body>
</html>
请帮忙!谢谢。
【问题讨论】:
-
控制台显示什么?
-
document.writeln("<tr><td>+i+"</td><td>"+theArray[i]+"</td></tr>");这一行甚至像问题中的正则表达式一样突出显示。你忘记了"。这是一个错字。 -
另外,那些
document.writeln行将导致无效的HTML,因为HTML标签会自动关闭 一旦它们被写入页面。 -
<head><body>---</head></body>???难怪什么都没有显示。应该是<head>------</head><body>-----<body>。 -
那我应该改用什么呢?
标签: javascript html arrays regex syntax-error