最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Use of CODE tag in HTML, How to I get it to display the code? - Stack Overflow

programmeradmin1浏览0评论

Quick question, If I want to document some code on a basic HTML and put that within a CODE tag, how can I quickly convert the code between those tags when the page renders to display properly? I know I can write a javascript find and replace and search through the string over and over until its done replacing all the characters, but is there a better way?

Or, is there a jQuery way to do it if I need to use javascript?

Quick question, If I want to document some code on a basic HTML and put that within a CODE tag, how can I quickly convert the code between those tags when the page renders to display properly? I know I can write a javascript find and replace and search through the string over and over until its done replacing all the characters, but is there a better way?

Or, is there a jQuery way to do it if I need to use javascript?

Share Improve this question edited Jun 1, 2009 at 19:00 GEOCHET 21.3k15 gold badges77 silver badges99 bronze badges asked Jan 26, 2009 at 15:45 UserUser 3,7926 gold badges29 silver badges23 bronze badges 1
  • Can you explain what you mean when you say 'display properly'? – ForYourOwnGood Commented Jan 26, 2009 at 16:04
Add a ment  | 

2 Answers 2

Reset to default 7

I think the <code> tag is more for displaying with a certain font, rather than layout. <code> seems to just use a monospaced font.

You might be looking for the <pre> tag (for pre formatted). That will preserve line breaks and spaces.

Unless the code you are trying to display is HTML code itself, then I think you'd have to change all the <'s to &lt;'s ahead of time

Sounds like you may be looking for syntax highlighting. Take a look at google's syntax highlihter

发布评论

评论列表(0)

  1. 暂无评论