mootools--Study notes (1)

Source: Internet
Author: User

1, selectors.

$ ("id"): ID selector, select only the ID name element, when selected, do not write the id name prefix "#";

$$ ("*"): Mixed selector, applicable to all elements, usage is very similar to jquery.

2, Dom is ready.

/* The following is excerpted from the network (translation) */

We often use window.onload or body onload= "" to perform loading events on some pages.

Such as

Window. onload=myfunction;

There are some drawbacks to this approach: first, we have to wait for the picture in the page to be loaded before executing the script (JS). Also, if there are some events and code bound to the window on our page, they will overwrite each other.

MooTools has developed a solution for this situation. When the DOM in the page is ready, MooTools comes with a custom event called Domready.

Such as

Window. addevent(' Domready ', function(){
MyFunction();
});

When the DOM in the HTML page is loaded, theMyFunction executes immediately, and the other window and image are immediately followed.

What are the advantages of Domready:

* Allow your work page to load first.

* Allows you to use the same event with other scripts.

* Do not wait for the picture to finish loading.

Domready Demonstration

/*
MooTools Domready.
The other Styles.
1. Call the function directly.
2. The function is inside of anonomos function.
*/
Window.addevent ( ' Domready ' , myfunction< Span class= "Br0") //or.
window. addevent ( ' Domready ' ,  function ({
   myfunction< Span class= "Br0" ( })
function myfunction ( {
  alert ( "the DOM is ready.") /span>

"The above content belongs to their own translation, if the error please help to provide comments, thank you"

mootools--Study notes (1)

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.