<!-- Begin
//nLength为正方形的边长,nHollow为空心的边长
function printSquare(nLength, nHollow)
{
if (!nLength || !nHollow || nLength <= nHollow)
{
alert("参数不正确,请核对!")
return
}
for (var n = 0n <nLengthn++)
{
for(var i = 0i <nLengthi++)
{
if (n <nHollow || n >= nLength - nHollow)
{
document.write(" * ")
}
if (n >= nHollow &&n <nLength - nHollow)
{
if (i <nHollow || i >= nLength - nHollow)
{
document.write(" * ")
}
else
{
document.write(" ")
}
}
}
document.write("<br>")
}
}
window.onload = printSquare(12, 1)
// End -->
</SCRIPT>
var len = prompt("输入正方形的行数", 0)len = len >10 ? 10 : len
for(var i = 0i <leni++){
for(var j = 0j <lenj++){
document.write("*")
}
document.write("<br / >")
}
完全可以打出来的,你是不是做table的时候设置了border=0?那样就是没有的。另外如果你没有打印机,同样可以选择打印,打印机算则Microsoft XPS Document Writer就可以,能以文件形式保存,直接打开看打印效果。
当然你也可以使用第三方组件进行打印比如ScriptX.cab与Smsx.cab
打印代码可参考:http://chengyaofei1122.blog.163.com/blog/static/340691742009926438303/