使用jQuery同时控制四张图片的伸缩实现代码

复制代码 代码如下:

  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

  <html xmlns="http://www.w3.org/1999/xhtml">

  <head>

  <title></title>

  <style type="text/css">

  .imgclass

  {

  height:200px;

  width:200px;

  }

  .imgclass1

  {

  width:210px; height:210px;

  }

  table tr td

  {

  width:250px; height:250px;

  }

  </style>

  <script src="jquery-1.9.1.js" type="text/javascript"></script>

  <script type="text/javascript">

  $(function () {

  $('#Button1').click(function () {

  // 获取的是所有类型(tagname)为img的元素

  // $('img').show(3000);

  // $('img').hide(3000);

  // //获取的是所有class属性的值为“imgclass”的元素

  // $('.imgclass').hide(3000);

  // $('.imgclass').show(3000);

  // $("#img1, #img2, #Button1").hide(2000);

  // $("#img1, #img2, #Button1").show(2000); //一定是将所有id用一对''括起来,而不能每个id分别用引号括起来

  // //多个选择器既可以是id,也可以是id,tagname和classname的混合体

  // $("#img1, #img2, input").hide(2000);

  // $("#img1, #img2, input").show(2000);

  //改变图片样式

  $('#Button2').click(function () {

  // $('#img2').removeClass();//删除Id为img2的class样式

  $('#img2').addClass('imgclass1');//然后再添加一个样式,再次点击按钮操作图片时,由于此图片的样式已改,所以不发生变化

  })

  })

  })

  </script>

  </head>

  <body>

  <table>

  <tr><td><img alt="" id="img1" src="images/1.jpg" class="imgclass" /></td><td><img alt="" id="img2" src="images/2.jpg" class="imgclass" /></td></tr>

  <tr><td><img alt="" id="img3" src="images/3.jpg" class="imgclass" /></td><td><img alt="" id="img4" src="images/4.jpg" class="imgclass" /></td></tr>

  <tr><td></td><td>

  <input id="Button1" type="button" value="点我啊" /></td></tr>

  <tr><td></td><td> <input id="Button2" type="button" value="改变控件样式" /></td></tr>

  </table>

  </body>

  </html>