更新後的外部JS代碼下面 我試圖執行一個簡單的相冊。我的課的任務是將鼠標懸停在一個小圖像上,並在更大的框中顯示替代文字和圖像,並且當鼠標離開文本時,背景圖像應該顯示爲原始的 以下是html:執行事件時出錯
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Photo Gallery</title>
<link rel="stylesheet" href="css/gallery.css">
<script src = "js/gallery.js"></script>
</head>
<body>
<div id = "image">
Hover over an image below to display here.
</div>
<img class = "preview" alt = "Styling with a Bandana" src = "https://s3-us-west-2.amazonaws.com/s.cdpn.io/389177/bacon.jpg" onmouseover = "upDate(this)" onmouseout = "unDo()">
<img class = "preview" alt = "With My Boy" src = "https://s3-us-west-2.amazonaws.com/s.cdpn.io/389177/bacon2.JPG" onmouseover = "upDate(this)" onmouseout = "unDo()">
<img class = "preview" src = "https://s3-us-west-2.amazonaws.com/s.cdpn.io/389177/bacon3.jpg" alt = "Young Puppy" onmouseover = "upDate(this)" onmouseout = "unDo()">
</body>
</html>
,這裏是我的(碎)外部JavaScript片:
function upDate(PreviewPic){
var imageLarge= document.getElementById('image');
document.getElementById('image').innerHTML = PreviewPic.alt;
document.getElementById('image').backgroundImage =imageLarge.src;
}
function unDo(){
document.getElementById('image').innerHTML = "Hover over an image below to display here.";
}
所以發生了什麼(或者沒有發生)?您在開發者控制檯中遇到什麼錯誤?請注意,沒有'getElementByClass'這樣的函數。你的意思是'getElementsByClassName'? – j08691
用更新的JS功能(見上文)我得到在控制檯沒有錯誤,當我徘徊,但只有文字變化激活,圖像/背景沒有改變@ j08691 –