JQuery first experience (jquery recommended) _ jquery

Source: Internet
Author: User
Tags color identifier
Recently, I heard from my friends that JQuery is a good tool for writing JavaScript, with a market share of 70%. So I downloaded a copy and tried it. On the JQuery website, we found that this plug-in provides two versions for download. One is the original version, close to 120 K, and the other is to compress the water, nearly 60 K. I haven't done any application technology for a long time. I didn't expect so many new things. JavaScript can also compress moisture, so I also learned about the JavaScript Packer (this is an online link ), if you are interested, you can download it here.. NET, Perl, Wsh, and PHP.

Let's get back to the question. The compressed version of JQuery is indeed suitable for accelerating network transmission, but the compressed version of JQuery only has one line, which is not suitable for VCS (Version Control System) management. Therefore, we recommend that you use a non-compressed version before you release the product.

After creating a project on SVN, write a Readme file. Because configuration and other things are involved, it is not easy to read in plain text, so it is written in HTML. WPS (or Word) is not used for writing. It is also because of VCS. It is better to control non-binary text. However, the Header in HTML does not have the automatic number function of Word. If one is inserted in the middle of a pile of headers one day, it will disrupt all the subsequent numbers, which is painful to change. So I remembered JQuery and used it for serial numbers. By the way, I tried it.

01 $( Function() {
02 Var Indexs = [ 0 , 0 , 0 ];
03 $( ": Header" ). Each( Function() {
04 Var Content = $( This ). Html();
05 If( $( This ). Is( "H1")) {
06 Indexs [ 0 ] ++;
07 Indexs [ 1 ] = 0;
08 Content = "" + Indexs [ 0 ] + "." + Content;
09 } Else If( $( This ). Is( "H2")) {
10 Indexs [ 1 ] ++;
11 Indexs [ 2 ] = 0;
12 Content = "" + Indexs [ 0 ] + "." + Indexs [ 1 ] + "." + Content;
13 } Else If( $( This ). Is( "H3")) {
14 Indexs [ 2 ] ++;
15 Content = "" + Indexs [ 0 ] + "." + Indexs [ 1 ] + "."
16 + Indexs [ 2 ] + "." + Content;
17 }
18 $( This ). Html( Content);
19 });
20});

Haha, the effect is good. But in fact, this code is the second version. In the beginning, it was searched by h1, h2, and h3, which made it more difficult to handle. In particular, h3 is placed in a p class with content, and the: first filter is used when JQuery is used, like this:

Var H3 = $( This ). NextAll( ". Content: first" ). Children( "H3");

Later, I thought that many paths are replaced by variables, such as $ (PHP_HOME). It is better to add a color identifier, so I added such a piece of code in $ (function () {...}).

20
21 $( ". Path" ). Each( Function() {
22 Var Content = $( This ). Html();
23 Content = Content . Replace( /(\ $ \(.*? \))/ , "$1")
24 $( This ). Html( Content);
25 });

Fortunately, all my paths are packaged. You only need to find all. path objects and replace $ (...) with a regular expression.Okay.

In general, people familiar with CSS wrote JQuery very quickly. Let's take a look at a simple tutorial and look at the JQuery document. In just an hour, we can learn JQuery and it is quite useful. No wonder so many people like it!

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.