In jquery, dom operations and event instances are used to learn the effects of the yahoo Mail logon box.

Source: Internet
Author: User
Recently, I tested dom operations in jquery and events and animation methods in jquery. I wanted to elaborate on every method to introduce it, but it was boring to write it like this.

The advantage of jquery is that simple code can bring a better user experience.

So I will look for some practical examples to introduce them. The following describes the operations and events used in this section.

Html code:



Jquery code:

The Code is as follows:


$ (Document). ready (function (){
$ ('# Address'). focus (function (){
Var add_value = $ (this). val ();
If (add_value = "Enter the email address "){
$ (This). val ("");
}
})
$ ('# Address'). blur (function (){
Var add_value = $ (this). val ();
If (add_value = ""){
$ (This). val ("Enter your email address ");
}
})
});


The result is that the value in the address box is cleared when the address box gets the mouse focus. When the mouse focus is lost, the address box restores the default settings.

Describes the jquery events used here:

Focus () is triggered when the jquery object gets the mouse focus, and blur () is triggered when the jquery object loses the mouse focus.

This section describes other mouse events. Mouseover () is triggered when the mouse moves into the object. Mouseout () is triggered when the mouse moves out of an object. Mousemove () is triggered when the mouse moves in the object.

The dom operations of jquery used:

Val () is to get the value of the element value, you can also set the value of the element value. This method for obtaining and setting in a function is very common in jquery.

Class is also html (), text (), heigth (), width (), css (), attr () and so on.

Html () and text () are distinguished here ()

Html () is relative to the html code in the object, while text () is only the text content in the object

For example

Differences



Certificate ('p'0000.html (). The result is Differences

$ ('P'). text (). The result is different

The introduction and expansion of this instance mentioned above.
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.