JS菱形镂空

<!DOCTYPE html>
<html>
 
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
.container {
float: left;
font-size: 32px;
}
 
.container span {
display: inline-block;
width: 32px;
}
</style>
</head>
 
<body>
 
<!--<div class="container">
<script type="text/javascript">
for(var i=0;i<4;i++){
//输出空格
for(var j=0;j<4-i-1;j++){
document.write("<span></span>");
}
//输出*
for(var j=0;j<2*i+1;j++){
document.write("<span>*</span>");
}
//换行
document.write("<br/>");
}
for(var i=0;i<3;i++){
//输出空格
for(var j=0;j<i+1;j++){
document.write("<span></span>");
}
//输出*
for(var j=0;j<5-2*i;j++){
document.write("<span>*</span>");
}
//换行
document.write("<br/>");
}
</script>
</div>-->
 
<script type="text/javascript">
for(var x = 0; x < 30; x++) {
document.write("<div class='container'>");
for(var i = -3; i <= 3; i++) {
var absi = Math.abs(i);
for(var j = 0; j < absi; j++) {
document.write("<span></span>");
}
for(var j = 0; j < 7 - 2 * absi; j++) {
if(j==0||j==7-2*absi-1)
document.write("<span>*</span>");
else
document.write("<span></span>");
}
document.write("<br/>");
}
document.write("</div>")
}
</script>
</body>
 
</html>
posted @ 2017-12-18 12:38  燕林夕  阅读(616)  评论(0编辑  收藏  举报