如何在javascript

时间:2015-07-10 06:45:57

标签: javascript html

<!DOCTYPE html>
<html>

<head>
    <title>multiplication table</title>
</head>

<body>
    <script type="text/javascript">
    var i, j;
    var m = 1;

    for (i = 1; i <= 10; i++) {
        for (j = 1; j <= 10; j++) {
            document.write(i * j);
        }
        document.write("\n");
    }
    </script>
</body>

</html>

输出:

  

12345678910 2468101214161820 36912151821242730 481216202428323640   5101520253035404550 6121824303642485460 7142128354249566370   8162432404856647280 9182736455463728190 102030405060708090100

它在不打印新行的情况下提供输出。我想在不使用

的情况下执行此操作

6 个答案:

答案 0 :(得分:4)

使用@font-face { font-family: 'robotoslab'; src: url('../fonts/robotoslab-regular.eot'); src: url('../fonts/robotoslab-regular.eot?#iefix') format('embedded-opentype'), url('../fonts/robotoslab-regular.woff') format('woff'), url('../fonts/robotoslab-regular.ttf') format('truetype'), url('../fonts/robotoslab-regular.svg#robotoslab') format('svg'); font-weight: normal; font-style: normal; } @font-face { font-family: 'robotoslab-bold'; src: url('../fonts/robotoslab-bold-webfont.eot'); src: url('../fonts/robotoslab-bold-webfont.eot?#iefix') format('embedded-opentype'), url('../fonts/robotoslab-bold-webfont.woff') format('woff'), url('../fonts/robotoslab-bold-webfont.ttf') format('truetype'), url('../fonts/robotoslab-bold-webfont.svg#robotoslab-bold') format('svg'); font-weight: normal; font-style: normal; } @font-face { font-family: 'robotoslab-light'; src: url('../fonts/robotoslab-light-webfont.eot'); src: url('../fonts/robotoslab-light-webfont.eot?#iefix') format('embedded-opentype'), url('../fonts/robotoslab-light-webfont.woff') format('woff'), url('../fonts/robotoslab-light-webfont.ttf') format('truetype'), url('../fonts/robotoslab-light-webfont.svg#robotoslab-bold') format('svg'); font-weight: normal; font-style: normal; }` 在新行上打印文字。当您将内容放在<br />中时。 DOM只会添加一个空格而不是换行符。

\n

示例:

document.write("<br />");

答案 1 :(得分:1)

在代码中代替 document.write(“ \ n”); ,添加document.write(“

代码在这里-

<!DOCTYPE html>
<html>
<head>
    <title>multiplication table</title>
</head>

<body>
    <script type="text/javascript">
    var i, j;
    var m = 1;

    for (i = 1; i <= 10; i++) {
        for (j = 1; j <= 10; j++) {
            document.write(i * j);
        }
        document.write("<br/>");
    }
    </script>
</body>

</html>

答案 2 :(得分:1)

var i, j;
var m = 1;

for (i = 1; i <= 10; i++) {
  for (j = 1; j <= 10; j++) {
    document.write(i * j + "\n\n");
  }
  document.write("<br />");
}

答案 3 :(得分:0)

<div class="container"> <img class="photo"> <div class="vertical_shadow"> </div> <div class="info"> </div> <div class="memo"> </div> </div> <style> .container{ position: relative; background-color: pink; width: 480px; height: 120px; } img, div{ position: relative; float: left; width: 120px; height: 120px; background-color: black; } .vertical_shadow{ position: absolute; left: -60px; background-color: green; } .info{ left: -60px; position: absolute; background-color: blue; } .memo{ position: absolute; background-color: red; } </style> 替换为document.write("\n");

请参阅小提琴:“PEP 0343

答案 4 :(得分:0)

<html>
<body>
  <script type="text/javascript">
     var i, j;
     var m = 1;
      for (i = 1; i <= 10; i++) {
       for (j = 1; j <= 10; j++) {
       document.write(i * j);
       }
      document.write("<br />");
     }
  </script>
</body>
</html>

答案 5 :(得分:0)

您是否尝试过<br/><br><br/>?但是,应该根据此来源支持<br>

赞:document.write("<br/>")

Supported HTML tags