Decompress jquery-syntax-3.1.1.zip, put public in our own directory, introduce the following three js in the web page (http://download.csdn.net/detail/liumengcheng/7344667)
Copy codeThe Code is 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 codeThe Code is as follows:
<Div id = "div_configXML" style = "float: right; width: 600px;">
</Div>
Js section:
Copy codeThe Code is as follows:
// The default configuration file type is xml.
Var fileType = "xml ";
// When an object 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 syntax coloring is required multiple times and the selected files are different each time,
// Delete the original pre element each time and add a new pre. syntax must be dynamically obtained based on the filename suffix.
// Note: Do not directly locate the pre, because the pre element disappears after each rendering, so here I use a div to put the pre, each time you clear the pre, you only need to 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 ();
}
);
}
}
});
The following are:
Show xml files
Display java files