Using jquery can: 1. Obtain DOM elements conveniently and quickly; 2. Dynamically modify the page style; 3. Dynamically change the DOM content; 4. Respond to user interaction; 5. Add dynamic effects to the page; 6. Unify Ajax operations; 7. Simplify common JavaScript tasks, etc.
The operating environment of this tutorial: windows7 system, jquery1.10.0 version. This method is suitable for all brands of computers.
Recommended tutorial: jquery video tutorial
The jQuery library provides a universal (cross-browser) abstraction layer for web script programming, making it suitable for almost any script programming situation. jQuery can usually provide us with the following functions:
If you use pure JavaScript to traverse the DOM and find a certain part of the DOM, you will write a lot of redundant code. , while using jQuery only one line of code is enough. For example, to find all P tags in p with the .content class style applied, you only need the following line of code:
$('p.content').find('p');
Using jQuery we can dynamically Modify the page's CSS even after the page is rendered. jQuery can still change classes or individual style attributes in certain parts of the document. For example, find the first li sub-tag of all ul tags on the page, and then add a style named active to them. The code is as follows:
$('ul > li:first').addClass('active');
Use jQuery We can easily modify the page DOM, for example, add a link to the element with the ID "container":
$('#container').append('<a href="more.html">more</a>');
jQuery provides various interception methods appropriate way to handle page events (such as a user clicking a link) without having to break up the HTML code with event handlers. Additionally, its event handling API eliminates browser inconsistencies that often plague web developers.
$('button.show-details').click(function() { $('div.details').show(); });
The above code means: add a click event to the button element using the .show-details style. The event is: display p using the .details style.
The built-in batch of effects such as fade-in and erasure in jQuery, as well as a toolkit for making new effects, provide convenience for this.
$(function () { $("#btnShow").click(function () { $("#msubject").hide("slow"); }); });
jQuery unifies the Ajax operations of multiple browsers, allowing developers to focus more on server-side development.
function (data, type) { // 对Ajax返回的原始数据进行预处理3 return data // 返回处理后的数据4 }
In addition to these fully document-specific features, jQuery also improves upon basic JavaScript data structures (such as iteration and array operations, etc.).
$.each(obj, function(key, value) { total += value; });
For more programming-related knowledge, please visit: Programming Teaching! !
The above is the detailed content of What can you do with jquery. For more information, please follow other related articles on the PHP Chinese website!