View Single Post
Old 08-14-2009, 10:44 AM   PM User | #6
Amphiluke
Regular Coder

 
Amphiluke's Avatar
 
Join Date: Jul 2009
Posts: 312
Thanks: 3
Thanked 89 Times in 89 Posts
Amphiluke is on a distinguished road
If use pre instead of code then it works in IE too!
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
   <meta http-equiv="content-type" content="text/html;charset=utf-8" />
   <title>Template</title>

   <style type="text/css">
      .hilightkw {
         color: #0000FF;
      }
      .hilightcomm {
         color: #008000;
      }
   </style>
   
<script type="text/javascript">
   var vbKeywords = new Array("If","Then","Else","ElseIf","End");
   function HiLightCode(codeBlock) {
      var _code = codeBlock.innerHTML;
      var re = / /g;
      _code = _code.replace(re, "&nbsp;");
      for (var i = 0; i < vbKeywords.length; i++) {
         var re = new RegExp(vbKeywords[i], "gi");
         _code = _code.replace(re, "<span class=\"hilightkw\">" + vbKeywords[i] + "</span>");
         delete re;
      }
      var lines = _code.split("\n");
      var outputCode = "";
      for (var i = 0; i < lines.length; i++) {
         var re = new RegExp("('.+)");
         outputCode += lines[i].replace(re, "<span class=\"hilightcomm\">$1</span>") + "<br />";
         delete re;
      }
      codeBlock.innerHTML = outputCode;
   }
   function HiLightAll() {
      var _codes = document.getElementsByTagName("pre");
      for (var i = 0; i < _codes.length; i++) {
         if (_codes[i].className == "vb") HiLightCode(_codes[i]);
      }
   }
   window.onload=HiLightAll;
</script>
   
</head>

<body>
<div>
<pre class="vb">
If iVar = 1 Then
  Text1.Text = "Satu" 'This is comment
ElseIf iVar = 2 Then
  Text1.Text = "Dua"
End If
</pre>
<pre class="vb">
If iVar = 1 Then
  Text1.Text = "Satu" 'This is comment
ElseIf iVar = 2 Then
  Text1.Text = "Dua"
End If
</pre>
</div>

</body>

</html>
Quote:
Would you give the code comments for each line in that code for me... I'm still newbie here
Sorry, time is lacking for a full explanation. Maybe later.
__________________
I am still learning English
Amphiluke is offline   Reply With Quote