首页 > 技术文章 > JavaScript之菱形打印

caidupingblogs 2015-10-31 12:20 原文

很高兴来到博客园!迈入这座知识的殿堂,实是幸运。这是我的第一篇博客,开启丰富有趣的学习之旅,同时,我希望和大家一起学习一起进步,Let‘s go!

<!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>
<center>
<script language="javascript">
var k=prompt("请输入打印行数:","");
for(var i=1;i<=k;i++){
for(var j=0;j<i;j++){
    document.write("*   ");
    }
    document.write("<br/>");
 
}
for(var i=k-1;i>0;i--){
for(var j=0;j<i;j++){
    document.write("*   ");
    }
    document.write("<br/>");
 
}
</script>
</center>
</body>
</html>

If reference to indicate the source:caiduping

推荐阅读