<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>等腰三角形</title>
</head>
<body>
<input type="text" name="" id="productName">
<input type="button" value="啊哈" name="btn" onclick="Triangle();">
<div id="test"></div>
<script type="text/javascript">
function Triangle() {
var length = document.getElementById("productName").value;//10;
var content = "";
for (var i = 0; i < length; i++) {
for (var d = 0; d < length - i; d++) {
content = content + " ";
//document.write(" ");
}
for (var e = 0; e < i * 2 + 1; e++) {
content = content + "*";
//document.write("*");
}
content = content + "<br/>";
//document.write("<br/>");
}
document.getElementById("test").innerHTML = content;
}
</script>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<script type="text/javascript">
var large=10; //设置行数
for(var i=0;i<large;i++)
{
p=i*2+1;
for(var d=0; d<large-i; d++){
document.write(" "); //注意,这里一定要使用全角中文空格,否则会出现直角三角形,而不是得等腰三角形(百度字面不支持中文空格,回去自己改下)
}
for(var e=0; e<i*2+1; e++){
document.write("*");
}
document.write("<br/>");
}
</script>
</body>
</html>