簡體   English   中英

<PRE> TAG不起作用?

[英]<PRE> TAG doesn't work?

在這里,我正在做的事情是通過在“ pre”標簽之間包裹來打印我的javascript代碼,如下所示:

<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

為什么會這樣? 我怎樣才能使“ pre ”標簽起作用?

您應該使用&lt; 代替< 同樣,使用&gt; 用於>&amp; 用於&以HTML格式顯示時。

您的for循環將類似於:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM