1 <html xmlns="http://www.w3.org/1999/xhtml">
2 <head>
3 <script type="text/javascript" src="jquery.js"></script>
4 <script type="text/javascript">
5 $(document).ready(function () {
6 $(".ex.hide").click(function () {
7 $(this).parents(".ex").hide("slow");
8 });
9 });
10 </script>
11 <!--样式定义-->
12 <style type="text/css">
13 div.ex
14 {
15 background-color:#e5eecc;
16 padding:7px;
17 border:solid 1px #c3c3c3;
18 }
19 </style>
20
21 </head>
22 <body>
23 <h3>Island Trading</h3>
24 <div class="ex">
25 <button class="hide" type="button">Hide me
26 </button>
27 <p>Contact:Helen Bennett<br />
28 Garden House Crowther Way<br />
29 London
30 </p>
31 </div>
32
33 <h3>Pairs Trading</h3>
34 <div class="ex">
35 <button class="hide" type="button">Hide me</button>
36 <p>Contact:Marie Bertrand<br />
37 265,Boulevard Charonne<br/>
38 Pairs
39 </p>
40 </div>
41 </body>
42 </html>
注意用空格隔开
$(".ex .hide").click(function () {
$(".ex .hide").click(function () {
上面回答的是一个原因 还有你那个jquery.js的路径是否引用成功了 都是需要检查一下的
选择多个 用空格隔开
选择器的问题
$('.ex.hide') 是选择 class="ex" 且 class="hide" 的元素,即 class='ex hide'。
你的情况应该用后代选择器(空格)或者子选择器(>号),如$('.ex .hide')或者$('.ex>.hide')