我在下面有这段代码:
<html>
<head>
<title> Eloquent Javascript Ex 2 </title>
<script language = "javascript">
/*
function twoPowerTen()
{
var result = 1;
var counter = 0;
while( counter < 10 )
{
result = 2 * result;
document.writeln( result );
counter = counter + 1;
}
}
int limit = 1;
for( int y = 0; y < 5; y++ )
{
for( int x = 0; x < limit; x++ )
{
System.out.print( "*" );
}
System.out.println();
limit = limit + 1;
}
*/
function drawTriangle()
{
var limit = 1;
for( var y = 0; y < 5; y++ )
{
for( var x = 0; x < limit; x++ )
{
document.write( "*" );
}
document.write( "<br>" );
limit = limit + 1;
}
}
function whileDrawTriangle()
{
var limit = 1;
var x, y = 0;
while( y < 5 )
{
while( x < limit )
{
document.write( "*" );
x++;
}
limit = limit + 1;
y++;
}
}
</script>
</head>
<body>
<input type = "button" value = "Draw # Triangle" onClick = "whileDrawTriangle()" />
</body>
</html>
当我按下按钮时,它似乎不想运行 - 它应该在屏幕上打印一个三角形的星号。顺便说一句,我知道 HTML 的构造不是很好,但关键是要实现基本的 javascript,因为我正在掌握它的基础知识。
有什么问题?