Jquery nonsense series tutorial (1) getting started

Source: Internet
Author: User

This article from (http://blog.csdn.net/wansijie/archive/2009/06/22/4288036.aspx)

Preface
Shells (the author of this article) also belong to the type that will just use jquery. There are also many problems encountered during the learning process, especially when getting started. I have been preparing to write some articles about jquery, but I am afraid that my writing and expression skills are limited, and I am afraid that I will be brave enough. if there are any mistakes or inappropriate understandings in the article, I hope the majority of friends will directly point out criticism.

The purpose of this article is to teach humans to fish as well as to teach humans to fish. I will only talk about the key part. It is impossible to talk about every function in jquery, because many function shells have never been used in practical applications. but when we get caught, do we still need to worry about fish !?

BTW: Shells assume that you have mastered basic JavaScript Application capabilities and basic CSS knowledge.

What is jquery?

Jquery is just a JS File

People always report curiosity and rejection to their new business. shells are the same when they first started learning. They want to know what they want and are afraid they will not learn. In fact, jquery is very simple.

Jquery is actually a toolkit. Many common functions have been encapsulated by good people. We really need to call them directly (a bit similar to the SDK). We will not discuss the specific internal principles and implementations. it is very easy to remember jquery.

Currently jquery latest release version 1.32, official: http://docs.jquery.com/Downloading_jQuery

This series of tutorials is based on version 1.32.

Jquery has two versions:

The uncompressed version is mainly used in development.

The other is minified. After the development is complete, you can use this version.

Differences between the two versions

The file size is different, and the end user can reduce the waiting time for JS download during browsing.

The size of uncompressed files is 118kb.

Minified file size: 56kb

What does jquery bring to us?

1. standing on the shoulders of giants

People have invented the wheel, and we don't have to create one ourselves.

2. Powerful Bom, Dom, CSS, and event operation capabilities

I usually use CSS and Dom operations, which is really convenient.

3. More concise code

My own personal experience. For example, the tr parity in a table is two colors. If I use JavaScript to code dozens of lines, jquery only needs two lines.

4. browser independence

After Javascript development, we know that JavaScript behavior in different browsers is sometimes different. We have to write the corresponding code for different browsers. jquery has been internally processed in this method. We just need to use it.

5. Good Performance

I know myself, at least the JavaScript code I write is less efficient than jquery.

How to Use jquery

I was scared when I used jquery for the first time. I don't know how to use it. It's actually very simple. Here is an example .:)

Create an HTML file, such as index.html and put it in the same directory as the jquery library file jquery-1.3.2.js (in fact, put that can be)

First, we solve jquery reference. The Code is as follows:

<HTML>

<Head>

<Title> jquery test </title>

<Script language = "JavaScript" src = "jquery-1.3.2.js"> </SCRIPT>

</Head>

<Body>

</Body>

</Thml>

The line of code in red completes jquery reference, simple!

Now we can extend the function to make index.html display a table, and the color of each row in the table is odd or even. That is, the odd row is a color, and the even row is another color.

Index.html code structure:

<HTML>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> jquery test </title>
<Style type = "text/CSS">

/* Even rows in the table */

. Tabeven {
Background: # ff0000;
}

/* Odd rows in table */

. Tabodd {
Background: #00ff00;
}
</Style>
<Script language = "JavaScript" src = "jquery-1.3.2.js">
</SCRIPT>
<Script language = "JavaScript" type = "text/JavaScript">
// <! [CDATA [
$ (Document). Ready (function (){
$ ("# Tabtest TR: Even"). addclass ("tabeven ");
$ ("# Tabtest TR: odd"). addclass ("tabodd ");
});
//]>
</SCRIPT>
</Head>
<Body>
<Table id = "tabtest">
<Tbody>
<Tr>
<TD> quickbuy Internet _ 1 </TD>
<TD> 1 </TD>
</Tr>
<Tr>
<TD> quickbuy Internet _ 2 </TD>
<TD> 1 </TD>
</Tr>
<Tr>
<TD> quickbuy Internet _ 3 </TD>
<TD> 1 </TD>
</Tr>
<Tr>
<TD> quickbuy Internet _ 4 </TD>
<TD> 1 </TD>
</Tr>
<Tr>
<TD> FMCG _ 5 </TD>
<TD> 1 </TD>
</Tr>
</Tbody>
</Table>
</Body>
</Thml>

The effect is as follows:

Code parsing:

$ (Document). Ready (function (){
$ ("# Tabtest TR: Even"). addclass ("tabeven ");
$ ("# Tabtest TR: odd"). addclass ("tabodd ");
});

$ (Document ). the role of ready is very simple. It is to wait for all the pages to be loaded internally and then execute JavaScript code (don't forget that jquery is also JavaScript code). This function is used in almost all the code that uses jquery. because if we have dom operations in JavaScript code and the entire DOM framework has not been fully established before the webpage is fully read, the previous Dom operations are invalid.

$ ("# Tabtest TR: Even"). addclass ("tabeven"); adds a CSS style named tabeven to the even row of the table whose ID is tabtest.
$ ("# Tabtest TR: odd"). addclass ("tabodd"); adds a CSS style named tabeven to the odd row of the table whose ID is tabtest.

Finally, Beginners should never feel overwhelmed by unfamiliar code. Remember that jquery is very simple.

 

Finally, related comments:

 

1.The building owner writes so far that jqueryhas The. CSS method $ (function () {$ ("# tabtest TR: Even" ).css ("background", "# ff0000"); $ ("# tabtest TR: odd ").css (" background "," #00ff00 ");})
2. Write well, but it is better to add some comparisons with Javascript methods, for example, $ (document). Ready is onlord () in JavaScript ().
3. post recommended by netizens
Learning jquery (I) from scratch
Learning jquery (2) omnipotent selector from scratch
Learning jquery from scratch (3) Managing jquery packaging Sets
Learning jquery from scratch (4) using jquery to operate on attributes and styles of Elements
Learning jquery (5) Events and event objects from scratch
Learning Ajax in jquery (6) from scratch
Learning jquery (7) jquery animation from scratch-let the page go!
Learning jquery (8) Plug-in from scratch: jquery implementation solution
Learning jquery (9) jquery tool functions from scratch
Learning jquery (10) Common jqueryui functions from scratch
Learning jquery (11) practical form verification and Automatic completion prompt plug-in from scratch
4. The author has been released in practice: http://topic.csdn.net/u/20090629/22/d8171579-b34a-4ca3-b92d-83b92c0c29b3.html? 492

 

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.