當前,具有鼠標懸停將鼠標懸停後將div更改爲紅色的功能。我想改變這個來彈出一個提醒,而這個提示顯示了div內的文本。如何在鼠標懸停事件上顯示警報
我試圖調用一個函數來調用警報
<img onmouseover='getAlert(this)' class='calPicSmile' src= 'img/" + calImg + ".png' height= '20' width= '20'>
以及
document.getElementsByClassName("calPicSmile").onmouseover = function() {getAlert()};
function getAlert(){
alert('test');
}
if (counter == day && month == curMonth && year == curYear) {
htmlContent += "<td class='dayNow alert' id='" + counter + monthIDName + "' onMouseOver='this.style.background=\"#FF0000\"; this.style.color=\"#FFFFFF\"' " + "onMouseOut='this.style.background=\"#FFFFFF\"; this.style.color=\"#FF0000\"'>" + counter + "<img class='calPicSmile' src= 'img/" + calImg + ".png' height= '20' width= '20'>" + "</td>";
} else {
htmlContent += "<td class='monthNow alert' id='" + counter + monthIDName + "' onMouseOver='this.style.background=\"#FF0000\"'" + " onMouseOut='this.style.background=\"#FFFFFF\"'>" + counter + "<img class='calPicSmile' src= 'img/" + calImg + ".png' height= '20' width= '20'>" + "</td>";
}
有沒有在你的代碼中的錯誤。它根本不起作用。您應該修復它,然後我們可以幫助您的問題。「未捕獲ReferenceError:計數器未定義」' – tommyO
它確實工作,但我並不想提供整個代碼。現在更新 –
爲什麼不更新你的代碼在jsbin –