How to Use jquery in JSP?

Source: Internet
Author: User

First, import the jquery package file.
Download.

Then introduce the package in JSP:

<MCE: script src = "lib/jquery-1.5.2.js" mce_src = "lib/jquery-1.5.2.js" type = "text/JavaScript"> </MCE: SCRIPT>

 

Next, introduce your own JS:

<MCE: script src = "My. js" mce_src = "My. js" type = "text/JavaScript"> </MCE: SCRIPT>

 

The content of my. js file is as follows:

$ (Document ). ready (function () {<br/> $ ("<div> <p> Hello </P> </div> "). appendto ("body"); </P> <p> $ ("# Stop" ).css ("background", "yellow "); </P> <p> $ ("Li "). toggle (<br/> function () {<br/> Functions (this).css ({"list-style-type": "disc", "color": "blue "}); <br/>}, <br/> function () {<br/> Functions (this).css ({"list-style-type": "disc", "color ": "Red"}); <br/>}, <br/> function () {<br/> Functions (this(.css ({"list-style-type": "disc ", "color": "gray"}); <br/>}< br/>); <br/> });

 

The content of myjquerytest.html on the test page is as follows:

<HTML xmlns = "http://www.w3.org/1999/xhtml"> <br/> <pead> <br/> <meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8 "/> <br/> <title> my jquery test </title> <br/> <MCE: script src = "lib/jquery-1.5.2.js" mce_src = "lib/jquery-1.5.2.js" type = "text/JavaScript"> </MCE: SCRIPT> <br/> <MCE: script src = "My. JS "mce_src =" My. JS "type =" text/JavaScript "> </MCE: SCRIPT> <br/> </pead> <br/> <body> <br/> <button> change colors </button> <br/> <br /> <span> span </span> <br/> <div> div1 </div> <br/> <div> div2 </div> <br/> <Div> div3 </div> <br/> <div> div4 </div> <br/> <Div id = "stop"> stop here </div> <br/> <div> div6 </div> <br/> <div> div7 </div> <br/> <div> div8 </div> <br/> <br/> <ul> <br/> <li> Li1 </LI> <br/> <li> li2 </LI> <br/> <li> li3 </LI> <br/> <li> LI4 </LI> <br/> <li> li5 </LI> <br/> </ul> <br/> </body> <br/> </ptml>

 

The running effect is as follows:

Before:

 

After:

 

Finally, it is worth noting that the introduction of jquery's package file must be prior to the introduction of JS, otherwise jquery will not work.

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.