使用jQuery同時控制四張圖片的伸縮實現代碼

來源:互聯網
上載者:User

複製代碼 代碼如下:
<!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>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.