如何在HTML代码中禁用脚本并仍然显示它们?

Deb*_*iti 2 html javascript tags html5

有什么方法可以用来显示[在html中]涉及脚本标记的代码段,同时阻止浏览器执行该脚本代码?

Mar*_*c B 5

编码所有<>字符,所以你最终得到

<div>
   <h2>Here's some JS code</h2>

   <pre>
      &lt;script type="text/javascript"&gt;
         var x = 7;
         var y = 10;
         if (x &lt; y) {
            alert('this alert will not fire!');
         }
      &lt;/script&gt;
    </pre>
</div>
Run Code Online (Sandbox Code Playgroud)