我是初學者,並寫了一些HTML代碼,但我需要的是,當我點擊div來改變背景圖片...我怎麼能做到這一點?事件onclick改變背景圖片
下面是代碼:
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
#kat1 {
background-image:url(ikoniceKategorije/07.jpg);
width:30px;
height:30px;
float:left;
}
#kat1:hover {
background-image:url(ikoniceKategorije/07h.jpg);
}
#kat2 {
background-image:url(ikoniceKategorije/06.jpg);
width:30px;
height:30px;
float:left;
}
#kat2:hover {
background-image:url(ikoniceKategorije/06h.jpg);
}
#kat3 {
background-image:url(ikoniceKategorije/05.jpg);
width:30px;
height:30px;
float:left;
}
#kat3:hover {
background-image:url(ikoniceKategorije/05h.jpg);
}
#kat4 {
background-image:url(ikoniceKategorije/04.jpg);
width:30px;
height:30px;
float:left;
}
#kat4:hover {
background-image:url(ikoniceKategorije/04h.jpg);
}
#kat5 {
background-image:url(ikoniceKategorije/03.jpg);
width:30px;
height:30px;
float:left;
}
#kat5:hover {
background-image:url(ikoniceKategorije/03h.jpg);
}
#kat6 {
background-image:url(ikoniceKategorije/02.jpg);
width:30px;
height:30px;
float:left;
}
#kat6:hover {
background-image:url(ikoniceKategorije/02h.jpg);
}
#kat7 {
background-image:url(ikoniceKategorije/01.jpg);
width:30px;
height:30px;
float:left;
}
#kat7:hover {
background-image:url(ikoniceKategorije/01h.jpg);
}
#div {
width:220px;
height:30px;
overflow:hidden;
}
</style>
</head>
<body>
<div id="div">
<div id="kat1"></div>
<div id="kat2"></div>
<div id="kat3"></div>
<div id="kat4"></div>
<div id="kat5"></div>
<div id="kat6"></div>
<div id="kat7"></div>
</div>
</body>
</html>
,或者你可以在上看到www.pluspon.com/kategorije.html我打算做。在懸停時更改圖片,然後點擊...感謝!
或一些其他的方式該怎麼做...也許jQuery或JavaScript? – 2012-02-13 15:24:48
您應該使用不是ID的類。並點擊後更改類。 – gdoron 2012-02-13 15:27:07
好的,但如何改變點擊類? – 2012-02-13 15:28:07