我想改變'img'類中的'im'和'desc'類的屬性。我將當前元素傳遞給javascript函數mOver()和mDown() 。當我鼠標懸停圖像的邊界以及文本它應該下面change.Here是我的代碼:改變一個類的元素的屬性
<html>
<head>
<style>
.img
{
margin:2px;
border:1px solid #0000ff;
height:90;
width:110;
float:left;
text-align:center;
}
.im
{
width:110px;
height:90px;
display:inline;
margin:3px;
border:1px solid #ffffff;
}
.desc
{
text-align:center;
font-weight:normal;
width:120px;
margin:2px;
}
</style>
<script>
function mOver(a)
{
a.style.border="10px solid #0000ff";
a.getElementByClassName("desc").innerHTML="Click on the image";
}
function mDown(a)
{
a.style.border="1px solid #ffffff";
a.getElementByClassName("desc").innerHTML="You have clicked already";
}
</script>
</head>
<body>
<div class="img" onmouseover="mOver(this)" onmouseout="mDown(this)">
<a target="_blank" href="abc.png">
<img class="im" src="abc.png"></a>
<div class="desc">ABC</div>
</div>
<div class="img" onmouseover="mOver(this)" onmouseout="mDown(this)">
<a target="_ blank" href="def.png">
<img class="im" src="def.png"></a>
<div class="desc">DEF</div>
</div>
</body>
</html>
圖片下方的文字並沒有改變,因爲它應該有。 我覺得是有毛病線
a.getElementByClassName("desc").innerHTML="You have clicked already";
我是比較新的JavaScript所以請讓我知道什麼是錯here.Anyways由於事先
它不應該是'getElementsByClassName'(複數)? – m90