recently, I 've been looking at jquery, just to deepen my previous learning of PHP.
the following link is the electronic version of the book I read, if you need to download: http://jumbofiles.com/9ovcjxmqyfbz
first explained the establishment of the test environment!
Firefox + firebug + XAMPP.
the first Firefox is Firefox, firebug is its plug-in, you can go to the http://getfirebug.com to download and install. It's very simple. skip this step.
XAMPP is a green Integrated Runtime Environment of PHP. After downloading and installing XAMPP, the installation process is completely foolish and skipped.
to insert the subject directly:
first you have to have jquery JS file, the latest version is 1.5.2, you can go to the http://jquery.org to download the latest.
Create an HTML file to try something:
<HTML>
Now, open the HTML file in Firefox and click the bug in the lower right of the browser's status bar. You may find different HTML files and try your best.
Now we can test some results in the console:
On the right is the input that calls jquery.CodeThe left is where the result is displayed.
Now we use $ to select Dom, similar to CSS syntax.
$ ("P"); // select an object based on the tag. This is the result of Selecting All <p>.
There are four <p>, right? Let's look at the source code of the above HTML file.
$ (". Foo"); // select the DOM whose class is foo.
Found two, one is <p> the other is <span>
$ ("# Bar"); // select the DOM whose ID is bar.
The ID of <p> is bar.
From the above example, we can see that the class uses. And the ID uses #
$ ("P. foo"); // select the DOM of <P class = "foo">
There is only one. This is a combination of tags and related attributes for query. have you learned?
$ (". Foo, # bar"); // select the DOM where class is foo or ID is bar.
There are three objects that meet the requirements. Remember to use commas to represent or
$ ("P span"); // searches for <span> objects located under <p>. uses spaces to represent hierarchies.
Of course we can also do this $ ("body P span"); Haha, there is no limit on the number of layers.
$ ("Body> span"); // search for the <span> object under <body>, that is, the son of span called the body. Note that it is not the grandson.
No. There is no direct span in the body, and all spans are embedded in P.
$ (". Foo + P"); // find that the class of the preceding element is Foo, and the class itself is the object of <p>.
In this way, you can find the results of $ (". Foo + P + # bar"); for the order of the combination?
$ ("P ~ # Bar "); // find the first <p> id named bar siblings.
The preceding P cannot be included in the result, because only the requesting siblings are found. $ ("P ~ P "); therefore, only three objects can be returned.
Next, let's talk about the filter, which is used for filtering: it is a selection condition.
$ ("P: Last"); // select the last p object $ ("P: First"); // select the first p object
This... this does not need to be explained...
$ ("P: Not (. Foo)"); // select the P object whose class is not Foo.
Three, because only one class in the four is Foo, 4-1 !!!!!
$ ("P: Even"); // select an even number of P objects $ ("P: odd"); // select an odd number of P objects
Note that the array starts from 0, that is, the numbers of P are 0, 1, 2, and 3, respectively. Therefore, 0 and 2 have no attribute p.
$ ("P: eq (3)"); // find the object with the serial number 3 in the p object
Yes, it is the last one, because we have said before, it needs to start from 0, and 3 is the last one in four objects.
$ ("P: Contains (there)"); // find all P objects with content containing there
No. replace it with this. Note that the content in contains is case sensitive. Therefore, this and this results are different.
$ ("P: Has (SPAN)"); // find the P object containing the span object
There are two.
$ (": Empty"); // search for all objects without text or sub-objects
Both objects only have no property content.
$ ("P: parent"); // search for all P objects of the father. If there are texts and sub-objects, the father is considered as the parent.
All P has text, so it is regarded as a father.
$ ("P: visible"); // search for all visible P objects
All can be seen
$ ("[Class = Foo], [ID! = Bar] "); // find all objects whose classes are Foo or whose IDs are not equal to bar
A lot, because we use or
There are two more. I will not talk about them if I have not understood them yet.
Add it next time.