---
title: "Jquery -章节1"
author: "Forestsai"
date: "2012-07-06T14:43:09Z"
tags: []
categories: ["Web前端"]
slug: "jquery-1"
draft: false
lastmod: "2012-07-06T14:43:09Z"
id: 1579705
url: "https://forestsai.iteye.com/blog/1579705"
---

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd](http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd)"&gt;  
&lt;html&gt;  
&lt;head&gt;  
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;  
&lt;title&gt;example&lt;/title&gt;  
&lt;style type="text/css"&gt;  
 body { width:760px; }                                                                 
 div { float:left; width:200px; margin:10px 20px; font-family:\\5FAE\\8F6F\\96C5\\9ED1; }  
 h3 { cursor:pointer; margin:0; border:1px solid black; color:white; background-color:green; }  
 ul { list-style:none; margin:5px 0; padding:5px 0; border:1px solid black; background-color:gold; display:none; }  
 .highlight{ color:black; background-color:gold; }  
&lt;/style&gt;  
&lt;script src="jquery-1.6.4.min.js" type="text/javascript"&gt;&lt;/script&gt;  
&lt;script type="text/javascript"&gt;  
 $(document).ready(function(){  
  $("h3").click(function(){  
  $(this).toggleClass("highlight")  
       .next("ul").toggle();  
  });  
 });  
&lt;/script&gt;  
&lt;/head&gt;  
&lt;body&gt;  
 &lt;div&gt;  
  &lt;h3&gt;sub 1(click me)&lt;/h3&gt;  
  &lt;ul&gt;  
   &lt;li&gt;param 1&lt;/li&gt;  
   &lt;li&gt;param 2&lt;/li&gt;  
   &lt;li&gt;param 3&lt;/li&gt;  
  &lt;/ul&gt;  
 &lt;/div&gt;  
 &lt;div&gt;  
  &lt;h3&gt;sub 2(click me)&lt;/h3&gt;  
  &lt;ul&gt;  
   &lt;li&gt;prama 1&lt;/li&gt;  
   &lt;li&gt;prama 2&lt;/li&gt;  
   &lt;li&gt;prama 3&lt;/li&gt;  
  &lt;/ul&gt;  
 &lt;/div&gt;  
 &lt;div&gt;  
  &lt;h3&gt;sub3 (click me)&lt;/h3&gt;  
  &lt;ul&gt;  
   &lt;li&gt;param 1&lt;/li&gt;  
   &lt;li&gt;param 2&lt;/li&gt;  
   &lt;li&gt;param 3&lt;/li&gt;  
  &lt;/ul&gt;  
 &lt;/div&gt;  
&lt;/body&gt;  
&lt;/html&gt;