什么是 jQuery?

jQuery 是一个快速、小巧且功能丰富的 JavaScript 库。它通过易于使用的 API,使 HTML 文档遍历和操作、事件处理、动画和 Ajax 等操作在多种浏览器中变得更加简单。凭借其多功能性和可扩展性的结合,jQuery 改变了数百万人的 JavaScript 编写方式。

简要回顾

DOM 遍历和操作

获取类名为 'continue' 的 <button> 元素并将其 HTML 更改为 'Next Step...'。

1
$( "button.continue" ).html( "Next Step..." )

事件处理

#button-container 中的任何按钮被点击时,显示其 CSS 中使用 display:none 隐藏的 #banner-message 元素。

1
2
3
4
var hiddenBox = $( "#banner-message" );
$( "#button-container button" ).on( "click", function( event ) {
hiddenBox.show();
});

Ajax

调用服务器上的本地脚本 /api/getWeather,带查询参数 zipcode=97201,并将元素 #weather-temp 的 html 替换为返回的文本。

1
2
3
4
5
6
7
8
9
$.ajax({
url: "/api/getWeather",
data: {
zipcode: 97201
},
success: function( result ) {
$( "#weather-temp" ).html( "<strong>" + result + "</strong> degrees" );
}
});

相关项目

jQuery UI

此项目处于维护模式。了解更多

jQuery Mobile

此项目已废弃。了解更多