Summary: The Use order of contemporary websites and web tends to rely on a large number of clientsJavascriptTo provide rich interaction. In particular, we do not discuss how to send asynchronous requests from new pages to data or echo them from scripts (or data systems) on the server. In this article, you will understand how the Javascript framework is faster and more simple to establish a highly interactive, responsive site and Web use order.
Introduction: Javascript is an object-oriented scripting language. It is constantly used as a web browser to select the sequential client script interface. Javascript allows web developers to program tasks with objects on webpages, providing a platform for operating these objects out of thin air. When Javascript is launched, it is usually used to provide some functionality that lacks channels, such as clock and scrolling text in the browser form bar. Another common feature is "rolover link", that is, when a user's mouse slides over an object, the color of the text or the background image changes. However, in recent years, Ajax has brought about a new interaction for network programming, and JavaScript has become increasingly useful. Before Ajax, any server processing or database access requires the whole page to be refreshed or a new page appears in the browser. This is not only a slow process, but also desperate for users and costly bandwidth and resources.
Ajax is Asynchronous JavaScript and XML. Although XML is not valid, AJAX can echo data in other formats except XML, such as JSON (JavaScript Object Notation ). The principle of AJAX is that an HTTP request is submitted to the Web server asynchronously, And the whole page is not refreshed, but only the echo content appears. On the contrary, developers usually use dom (Document Object Model) operations to modify a part of a web page, and the HTTP echo data will reflect these changes.
What is a javascript framework?
Javascript itself is a very powerful language. You don't need any rated framework to establish a rich Internet Use System (RIA) supported by it ). However, using JavaScript is not easy, primarily because of the appearance of various complications when trying to provide support for multiple browsers. Similar to HTML and CSS, different browsers have different JavaScript Execution Methods. Therefore, it is a nightmare to ensure cross-browser compatibility of your JavaScript code.
OneJavascript frameworkOr the library is actually a series of tools and functions, it can more easily happen cross-browser compatible JavaScript code. Each library has been rigorously tested in many popular latest web browsers. Therefore, you can fully believe that using any of these frameworks, your JavaScript-based Ria will be roughly the same in different browsers.
In addition to browser compatibility concerns, the Javascript framework can easily write code to retrieve, traverse, and manipulate DOM elements. They can not only provide a quick function to obtain the reference of a DOM element, but also allow chrysanthemum Dom traversal function chain to find parent, child, or any depth of sibling node elements. At the beginning, the Framework provides a series of functions to make it easier to manipulate these objects, allowing them to modify, add, or delete the content, or manipulate the style of the class to influence the appearance of the element. Processing can be said to be a nightmare. Therefore, JavaScript frameworks usually wrap browser events and provide a series of useful cross-browser functions to process them. Some frameworks also provide normalized things that represent the keyboard key code series (such as the ESC key, enter key, and cursor ).
All these functions are very useful. The javascript framework has played a major role in its recent popular Ajax usage. Like other aspects of JavaScript, each web browser tends to support Ajax in a different way, making Ajax support for all browsers a heavy task. Almost all JavaScript frameworks include necessary Ajax libraries. Generally, Ajax is provided to request and respond to objects. After evaluating the response, the DOM element is updated and a specific request is polling.
Typical features of a javascript framework
Now let's take a look at some of the functions of a few JavaScript frameworks. These features include:
- Selector
- Dom Traversal
- Dom operations
- Applicable Functions
- Incident Handling
- Ajax
To better interpret these features, I will list one or more examples of JavaScript frameworks: Prototype, jquery, Yui, extjs, and mootools. Although the execution of each framework is different from the syntax, the concept is similar. Each framework has a detailed api reference. You can refer to its decision on how to use the feature functions of these specific libraries.
Selector
A few JavaScript frameworks can select high-speed elements in some way. In general, these selector makes it faster to obtain an element, and allows you to determine the ID, class, element type, or pseudo-class selector to select an element.
For example, using common JavaScript, you can use the following code to obtain DOM elements with ID.
VaR theelement = Document. getelementbyid (the _ element ');
Like other frameworks, mootools provides a shortcut for performing this operation. In addition to selecting elements, mootools decides that a series of function functions extend the elements.
VaR theelement = $ (the _ element ');
$ Functions are available in multiple popular frameworks (not everything), and their syntax is similar. Prototype goes deeper to determine when the ID can select multiple elements and go to an element array. The syntax is as follows:
VaR elementarray = $ ('element _ one', 'element _ two', 'element _ Three ');
In the applicable function area, you will understand that some function iterations provided by the Javascript framework make our set easier.
In the preceding example, you must provide the ID of the element you want to select. But how do you select multiple elements? All images, each row of a table with a specific classname. Mootools (multiple other libraries) provides an easy way to do this -- $ function. In addition to the element ID, it can also accept the following parameters: element name, class name, and pseudo class selector. The task principle is similar to that of the $ function. For example, you can use the following code to obtain all images on a page:
VaR allimages =$ $ ('img ');
This will get all imag arrays in the document, and each decision $ function and the original function execution extension.
It is very useful to determine the tag to select an object, but suppose you only want to select its partial subset based on the element class. How can this be done? The same is very easy. In the following example, mootools selects the row whose class is "odd" in the table, which is useful for performing operations on each row (changing the color of each row in the table ).
VaR alloddrows =$ $ ('tr. odd ');
In reality, mootools provides a better way to perform row operations. In the preceding example, it is assumed that the class name "odd" is assigned to the odd row of the table ". The following code does not need to define any class names on each row of the table.
VaR alloddrows =$ ('tbody dd ');
This is an example of a pseudo-class selector, which goes to any object of the matching specification. In this example, the result is the child element of all odd rows in the tbody element of the page. Examples of other pseudo-class elements of mootools include:
- Checked all selected elements (for example, the selected check box );
- Enabled all available elements;
- Contains all include elements of text (passed as a parameter to the selector.
As mentioned above, not all JavaScript frameworks use the $ function to select DOM elements. In the third version of Yui (Yahoo User Interface), the following code is used to determine the ID to select the element (Note: yui3 must add the character # Before the ID #).
Similarly, it is suggested that the $ function is not used for selecting elements by TAG or class. In Yui, you should use y. All instead.
VaR alloddrows = Y. All ('tr. odd ');
Extjs works in the same way as the task. It is determined that the ID selects elements using the following syntax:
VaR theelement = ext. Get (the _ element ');
The syntax below is used to determine the elements obtained by TAG and class:
VaR alloddrows = ext. Select ('tr. odd ');
In the next chapter, you will understand how to use the Javascript framework to quietly traverse DOM objects. In other words, find the elements that have parent-child and sibling contact with the selected elements.
Reprint address: http://www.denisdeng.com /? P = 699
Address: http://www.ibm.com/developerworks/web/library/wa-jsframeworks/index.html