Decompression Jquery-syntax-3.1.1.zip, will be public in our own directory, in the Web page to introduce the following 3 JS (download address is http://download.csdn.net/detail/liumengcheng/7344667)
Copy Code code as follows:
<script type= "Text/javascript" charset= "UTF-8" src= "Scripts/jquery-1.8.2.js" ></script>
<script type= "Text/javascript" charset= "UTF-8" src= "Public/jquery.syntax.js" ></script>
<script type= "Text/javascript" charset= "UTF-8" src= "Public/jquery.syntax.cache.js" ></script>
HTML section:
Copy Code code as follows:
<div id= "Div_configxml" style= "float:right;width:600px;" >
</div>
JS section:
Copy code code as follows:
The default type of configuration file is XML
var filetype= "xml";
When a file in the tree is selected
$ (' #tree1 '). Tree ({
Onclick:function (node) {
if (Node.children==null | | node.children==undefined) {
var url= ". /hub/config/configread? " + ' ip= ' +ip+ ' &port= ' +port+ ' &file= ' +node.id;
var str=node.id;
FileType = str.substring (Str.lastindexof (".") +1,str.length);
Filetype=filetype.tolowercase ();
$.get (Url,{},function (data,textstatus) {
Because you need multiple syntax coloring, and each selected file is different,
So each time you want to delete the original pre element and add the pre, and syntax have to be dynamically based on the suffix of the filename.
Note: Do not position the pre directly, because the pre element will disappear after each rendering, so I use a div to put the pre, every time I clean the pre, just delete all the elements under the Div.
$ ("#div_configXML *"). Remove ();
var $pre =$ ("<pre id= ' configxml ' class= ' syntax ' +filetype+" ' > </pre> ');
$ ("#div_configXML"). Append ($pre);
$ ("#configXML"). Text (data);
$.syntax ();
}
);
}
}
});
Here is the effect chart:
displaying XML files
displaying Java files