Small selector problems in jQuery (new users will inevitably encounter)

Source: Internet
Author: User

Today, I learned how to use the selector according to the jQuery manual. I am going to try to write a user registration verification. I didn't expect to start a very small problem that made me difficult!

It is inevitable that new users will encounter very small details. In this article, we will only encourage them:

The test code is as follows:
Copy codeThe Code is as follows:
<Script type = "text/javascript" src = "jquery.1.11.0.min. js"> </script>
<Script type = "text/javascript">

Function checkUser () {// check the function of the user name
Alert ("OK"); // test...
}

$ (Document). ready (function (){

$ (": Text: first"). blur (function () {// triggered when the focus is lost

/** This is where I have been tossing for a long time. Of course, I want to obtain the user registration element, so I use

* The above selector does not work at all! Check the code and find that there is no error at all! What is the problem?

* Is there a problem with selector usage? I used the # id selector. It's OK! However, in theory, this selector is certainly okay!

* I used $ (": input: text") Again. Error! $ (": Input: eq (0)"); error! Sister's! Where is the problem?

* At this moment, I accidentally deleted a space in text and: first, and ran it! Try again

* A few selectors, all OK! After multiple tests, the following experiences are obtained:

* When using a combination selector with an internal inclusion relationship, no space is allowed between them! $ (": Text: first)" error! $ (": Text: first)

**/Correct! When using the hierarchical link combination selector, there must be spaces between them.
CheckUser ();

});

</Script>

</Head>
<Body>

<Form>
<Fieldset>
<Legend> registration page </legend>
Username <input type = "text"> <br>
Password <input type = "password"> <span> <br>
Password verification <input type = "password"> <br>
Email <input type = "text"> <span> <br>
<Input type = "submit" value = "register">
</Fieldset>
</Form>

</Body>
</Html>

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.