版本1:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script language="JavaScript">
function getIt(line) {
mystring = new String("");
for (i = 0; i < parseInt(line); i++) {
for (j = 0; j < (i + 1) * 2 - 1; j++)
mystring = mystring + "*";
mystring = mystring + "<br>";
}
document.getElementById("result").innerHTML = mystring;
}
</script>
</head>
<body>
<form name="myFrm">
输入行数:
<input type="text" name="line" size="12"/>
<br/>
<input type="button" value="计算"
onclick="getIt(document.myFrm.line.value)"/>
</form>
<div id="result" style="height:500pt;width:500pt;background-color: aquamarine;text-align:center;font-family:宋体;font-size:28pt"></div>
</body>
</html>
版本2:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script language="JavaScript">
function getIt(line) {
mystring = new String("");
for (i = 0; i < line; i++) {
for (j = 0; j < line-i-1; j++)
mystring = mystring + " ";
for (j = 0; j < (i + 1) * 2 - 1; j++)
mystring = mystring + "*";
mystring = mystring + "<br>";
}
document.getElementById("result").innerHTML = mystring;
}
</script>
</head>
<body>
<form name="myFrm">
输入行数:
<input type="text" name="line" size="12"/>
<br/>
<input type="button" value="计算"
onclick="getIt(document.myFrm.line.value)"/>
</form>
<div id="result" style="height:500pt;width:500pt;background-color: aquamarine;white-space:pre;font-size:28pt"></div>
</body>
</html>
版本3:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script language="JavaScript">
function getIt(line) {
mystring = new String("");
for (i = 0; i < line; i++) {
for (j = 0; j < line-i-1; j++)
mystring = mystring + " ";
for (j = 0; j < (i + 1) * 2 - 1; j++)
mystring = mystring + "*";
mystring = mystring + "<br>";
}
document.getElementById("result").innerHTML = mystring;
}
</script>
</head>
<body>
<form name="myFrm">
输入行数:
<input type="text" name="line" size="12"/>
<br/>
<input type="button" value="计算"
onclick="getIt(document.myFrm.line.value)"/>
</form>
<div id="result" style="height:500pt;width:500pt;background-color: aquamarine;font-size:28pt"></div>
</body>
</html>