在js中高亮js代码

On 07/31/2010, in javascript, by kilobug
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<script type="text/javascript">
function highlight(code){
 var regs = {
  'string':/((\"[^\"]+\")|(\'[^\']+\'))/gi,
  'comment':/(\/\/[^\n]+)/gi,
  'word':/(if|var|function|switch|case|return|break)/gi
 }
 for (var i in regs)
  code=code.replace(regs[i],'<font class="'+i+'">$1</font>');
 return code;
}
var a = highlight('var a = "aaaaa"; if () { return false; }');
alert(a);
document.write(a);
</script>
Tagged with:  

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

无觅相关文章插件,快速提升流量