Javascript或HTML中的新行? [英] New line in Javascript or HTML?

查看:84
本文介绍了Javascript或HTML中的新行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var symbol = prompt("Please choose a symbol");
var side = prompt("Choose the length of the square");
var count1 = 1;
var count2 = 1;
while (count1 <= side) {
    while (count2 <= side) {
        document.write(symbol);
        var count2 = count2 + 1;
    }
    document.writeln()
    var count2 = 1;
    var count1 = count1 + 1;
}

http://jsfiddle.net/kjQB9/36/

我正在使用上面的代码。我试图让JS从给定的输入中抽出一个盒子。我已经阅读了关于\ n \\\ and和
代码但我无法将它们放在某处以使线条形成正方形。例如,如果我输入*和3.我希望输出为:

I am working with the code above. I'm trying to get JS to draw a box out of a given input. I have read about the \n\r and
codes but I have not be able to place them somewhere to get the lines to form a square. For instance if I input * and 3. I want output to be:

***
***
***

但它显示为 *** ** * ***

我在哪里可以包含这些标签,是否应该用HTML或JS完成?

Where can I include these tags, and should it be done in HTML or JS?

推荐答案

使用< br> 标记进行休息。 \ r \ n 是换行符,但HTML会忽略大多数空格。

Use a <br> tag for a break. The \r or \n are line breaks, but HTML ignores most whitespace.

这篇关于Javascript或HTML中的新行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆