Jquery实现动态切换图片的方法
本文实例讲述了Jquery实现动态切换图片的方法。分享给大家供大家参考。具体实现方法如下:
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<title></title>
<styletype="text/css">
#tbl{border-collapse:collapse;border-top:1pxsolidred;border-left:1pxsolidred;margin:auto;}
#tbltd{border-collapse:collapse;border-bottom:1pxsolidred;border-right:1pxsolidred;}
#main{margin:0pxauto;border:1pxsolidyellow;}
</style>
<scriptsrc="jquery-1.6.2.min.js"type="text/javascript"></script>
<scripttype="text/javascript">
var$imgs;
var$tds;
$(function(){
$tds=$("#tbltd");
$tds.click(function(){
//说明:
//$("img",$(this))表示当前td下的img元素
//$("img",$(this).siblings("td"))表示当前td的所有兄弟元素(并且要求是td)下的img元素
$("img",$(this)).attr("src","../images/select.JPG");
$("img",$(this).siblings("td")).attr("src","../images/noselect.JPG");
});
}
);
</script>
</head>
<body>
<divid="main">
<tableid="tbl">
<tbody>
<tr>
<td><imgsrc="../images/noselect.JPG"/></td>
<td><imgsrc="../images/noselect.JPG"/></td>
<td><imgsrc="../images/noselect.JPG"/></td>
<td><imgsrc="../images/noselect.JPG"/></td>
<td><imgsrc="../images/noselect.JPG"/></td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
希望本文所述对大家的jQuery程序设计有所帮助。