<pre> TAG doesn&#39;t work?</pre>

时间:2015-03-17 08:14:50

标签: html pre

在这里,我正在做的是打印我的javascript代码,包括&#34; pre&#34;像这样的标签:

<pre>
    var sum = function(toSum) {
    var j = 0;
    for(var i=0; i<toSum.length; i++) {
        j = j + toSum[i];   
    }

    console.log("The sum of array is " + j);
};

sum([1,2,3,4]);

var multiply = function(toMultiply) {
    var j = 1;
    for(var i=0; i<toMultiply.length; i++) {
        j = j * toMultiply[i];  
    }

    console.log("The multiplication of array is " + j);
};

multiply([1,2,3,4]);
</pre>

但我实际得到的是:

var sum = function(toSum) {
var j = 0;
for(var i=0; i

为什么会这样?我怎样才能得到&#34; 预先&#34;标签工作?

1 个答案:

答案 0 :(得分:4)

您应该使用&lt;代替<。 同样,在以HTML格式显示时,&gt;使用>&amp;使用&

你的for循环将如下:

for(var i=0; i&lt;toSum.length; i++) {
...
}