初来乍到,写个JS小程序压压惊。以下为JS打印等腰三角形的简单例子。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>打印等腰三角形</title>
<script type="text/javascript">
window.onload = function(){
var
str = "",
oResult = document.getElementById("result"),
oCheck = document.getElementById("check");
oCheck.onclick = function(){
str = ‘‘;
var iLine = document.getElementById("line");
var oLine = iLine.value;
for(var i = 0;i < oLine;i++){
for(var j = 0;j < 2 * i - 1;j++){
str += ‘*‘;
}
str += "<br/>";
}
oResult.innerHTML = ‘<div style="text-align:center">‘ + str + "</div>";
}
}
</script>
</head>
<body>
请输入需要打印的等腰三角形行数<input type="text" id="line" /><input type="submit" id="check" /><br />
<div id="result"></div>
</body>
</html>