关于pre的问题

来源:5-1 HTML基础总结

慕雪1434180

2017-11-20 19:20:30

老师,不知道为什么我的这段代码很奇怪:当在循环表达式中,写成i<friuts.length(中间没有空格)的时候,不知道为什么不能完全显示pre中的内容,而当写成i<     friuts.length(中间有空格)的时候,就可以完全显示内容,这是为什么?求老师解答,谢谢老师,代码如下:

<!DOCTYPE html>

<html>

<head>

<title>div</title>

<meta charset="utf-8">

<link rel="shortcut icon" href="favicon.png" type="image/x-icon">

<style type="text/css">

.favorite{

background:grey;

color:white;

border:thin solid black;

padding:0.2em;

}

</style>

</head>

<body>

<div class="favorite">

<p>I like apples and oranges.</p>

</div>

<p>I like apples and oranges.</p>

<!-- pre -->

<pre><code>

var fruits=["apples","oranges","mangoes","cherries"];

for(var i=0;i<fruits.length;i++){

document.write("I like "+fruits[i]);

}

</code></pre>

</body>

</html>


写回答

1回答

小于飞飞

2017-11-21

如果想显示一段代码,注意这些特殊字符的处理如(< 号),html会解析为标签开始,所以想显示出来,要使用特殊字符编码,将<改成&lt; 试一试。

0

0 学习 · 36712 问题

查看课程