Sample Code for jquery-syntax dynamic syntax coloring

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.