---
title: "JQuery (2)"
author: "Roader123"
date: "2010-11-15T00:05:46Z"
tags: ["JavaScript", "jQuery"]
categories: ["Web前端"]
slug: "jquery-2"
draft: false
lastmod: "2010-11-15T00:05:46Z"
id: 811354
url: "https://roader123.iteye.com/blog/811354"
---

$()函数（JQuery 函数的别名）返回特别的JavaScript对象，它包含着与选择器相匹配的DOM元素的数组。该对象还包含大量预定义的有用的方法，能够用于该数组。

 

 

jQuery 的$()函数最常见的用途就是包装元素以便于操作。

它的另外一个功能就是作为几个通用的实用工具函数的命名空间前缀。

 

1.3.3文档就绪处理程序

一旦DOM树(而不是外部图像资源)加载完毕，就去激活代码的执行。

正式语法：

$(document).ready(function(){

  $("table tr:nth-child(even)").addClass("even");

});

 

简写形式：

$(function(){

  $("table tr:nth-child(even)").addClass("even");

});

 

1.3.5 扩展jQuery

 

$.fn.disable = function(){

  return this.each(function(){

    if(typeof this.disabled != "undefined") this.disabled= true;

  });

};

在这两个嵌套的函数中，两个this 分别指向不同的对象。