簡體   English   中英

使用Javascript顯示代碼段

[英]Display code snippet with Javascript

我希望能夠使用JavaScript打印帶有腳本標簽的代碼段。

這或多或少是我想要打印的:

<script src='URL type='text/javascript'></script><script>functionName();</script>

我試過了:

jQuery('selector').text("<pre><script src='URL type='text/javascript'></script><script>functionName();</script></pre>");

使用一些語法高亮(ex https://highlightjs.org/ )。

  <html> <head> <title>test</title> <!-- load highlight.js css & js --> <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.0.0/styles/default.min.css" rel="stylesheet" type="text/css" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.0.0/highlight.min.js" type="text/javascript"></script> </head> <body> <!-- set up your tag which want to highlight --> <pre><code class="xml"> &lt;script src='URL type='text/javascript'>&lt;/script>&lt;script>functionName();&lt;/script> </code></pre> <script> // initialize highlight hljs.initHighlightingOnLoad(); </script> </body> </html> 

暫無
暫無

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

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