1
因此,代碼的第一部分創建一個按鈕,單擊時顯示圖像。但是,代碼的第二部分應該是在懸停時使圖像更大,但它似乎不起作用。我通過控制檯運行這個鱈魚,它沒有給我任何東西。有任何想法嗎?爲什麼第二個事件監聽器不工作?
var button = document.getElementById("image");
var image = document.createElement("img");
button.addEventListener("click", function() {
image.setAttribute("src", "https://www.w3schools.com/css/trolltunga.jpg");
image.setAttribute("height", "400");
image.setAttribute("width", "500");
document.body.appendChild(image);
});
image.addEventListener("mouseover", function(){
image.style.width = "700";
image.style.height = "700";
})
正確的事件名稱爲['onmouseover' ](https://www.w3schools.com/jsref/event_onmouseover.asp)。 –