for(var i=0i<ni++){
var str = ""
for(var j=0j<n*2-1j++){
if(j==n-i-1||j==n+i-1||(i==n-1&&j%2==0)){
str+="*"
}else{
str+=" "
}
}
console.log(str)
}
<!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 + "&nbsp&nbsp&nbsp"
//document.write("&nbsp&nbsp&nbsp")
}
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=0i<largei++)
{
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("")
}
</script>
</body>
</html>