用js写输出星号直角三角形的代码
1个回答
展开全部
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="utf-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>document</title>
<script>
function paint(ul, n) {
for (var i = 0; i < n; i++) {
var newchild = document.createElement("li");
var str = '';
for (var j = 0; j < 2 * i - 1; j++) {
str += '*';
}
newchild.innerHTML = str;
ul.appendChild(newchild);
}
}
function run() {
var ul = document.getElementById("test");
ul.style.listStyle = 'none';
var len=document.getElementById("length");
paint(ul, len.value);
alert("done");
};
</script>
</head>
<body>
<input id="length" type="text" placeholder="输入边长"></input>
<input type="button" value="generate" onclick="run();"/>
<ul id="test">
</ul>
</body>
</html>
<html>
<head>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="utf-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>document</title>
<script>
function paint(ul, n) {
for (var i = 0; i < n; i++) {
var newchild = document.createElement("li");
var str = '';
for (var j = 0; j < 2 * i - 1; j++) {
str += '*';
}
newchild.innerHTML = str;
ul.appendChild(newchild);
}
}
function run() {
var ul = document.getElementById("test");
ul.style.listStyle = 'none';
var len=document.getElementById("length");
paint(ul, len.value);
alert("done");
};
</script>
</head>
<body>
<input id="length" type="text" placeholder="输入边长"></input>
<input type="button" value="generate" onclick="run();"/>
<ul id="test">
</ul>
</body>
</html>
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询