---
title: "第一个jQuery实例"
author: "yaasshole"
date: "2012-02-29T12:51:00Z"
tags: []
slug: "jquery"
draft: false
lastmod: "2012-03-03T11:07:06Z"
id: 1436867
url: "https://yaasshole.iteye.com/blog/1436867"
---

第一个jQuery实例

jQuery是一种优秀的JavaScript框架，它是轻量级的，还兼容各种浏览器。

&lt;%@ page language=*"java"* import=*"java.util.\*"* pageEncoding=*"utf-8"*%&gt;

&lt;%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%&gt;

&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt;

&lt;html&gt;

&lt;head&gt;

&lt;base href=*"*&lt;%=basePath%&gt;*"*&gt;

&lt;title&gt;My JSP 'example01.jsp' starting page&lt;/title&gt;

&lt;meta http-equiv=*"pragma"* content=*"no-cache"*&gt;

&lt;meta http-equiv=*"cache-control"* content=*"no-cache"*&gt;

&lt;meta http-equiv=*"expires"* content=*"0"*&gt;

&lt;meta http-equiv=*"keywords"* content=*"keyword1,keyword2,keyword3"*&gt;

&lt;meta http-equiv=*"description"* content=*"This is my page"*&gt;

&lt;!--

&lt;link rel="stylesheet" type="text/css" href="styles.css"&gt;

--&gt;

&lt;!-- 引入jQuery类库 --&gt;

&lt;script type=*"text/javascript"* src=*"*${pageContext.request.contextPath}*/js/jquery-1.7.1.js"*&gt;&lt;/script&gt;

&lt;/head&gt;

&lt;body&gt;

&lt;/body&gt;

&lt;/html&gt;

&lt;script type=*"text/javascript"*&gt;

//当窗体加载完毕 之后触发function匿名函数

$(document).ready(**function**(){

alert("hello");

});

//这个是以上的简写形式

$(**function**(){

alert("hi");

});

**匿名函数的介绍**

$就是jQuery对象 var jQuery=window.$

jQuery对象就是通过jQuery($())包装dom对象后产生的对象

dom的对象只能使用dom的属性和方法 jQuery的对象只能使用jQuery的属性和方法

$(document) 是jQuery对象

ready()方法就是jQuery对象的方法,ready是匿名回调函数

&lt;/script&gt;