2017-08-22 40 views
0

當前,具有鼠標懸停將鼠標懸停後將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>"; 
 

 
}

+0

有沒有在你的代碼中的錯誤。它根本不起作用。您應該修復它,然後我們可以幫助您的問題。「未捕獲ReferenceError:計數器未定義」' – tommyO

+0

它確實工作,但我並不想提供整個代碼。現在更新 –

+0

爲什麼不更新你的代碼在jsbin –

回答

1

沒有你必須發佈完整的代碼,你是否試圖實現這樣的事情?

function getAlert(image) { 
 
    alert('Here\'s an alert!') 
 
}
<img onmouseover='getAlert(this)' class='calPicSmile' src='https://images-production.global.ssl.fastly.net/uploads/photos/file/117262/michae-scott-quotes-5.jpg?auto=compress&crop=top&fit=clip&h=500&q=55&w=698' height='100' width='140'>

+0

這是我想要的,但是,它似乎是一個與Framework7(這是我用來創建我的應用程序)的問題。可能,使用鼠標懸停是錯誤的,但它確實可以使div變紅 –

2

<html> 
 
<body> 
 
<script> 
 
function Alert(e){ 
 
alert(e.target.innerText); 
 
}; 
 

 
</script> 
 

 
<div onmouseover="Alert(event)">Hover Me</div> 
 

 
</body> 
 
</html>

這是你想要的嗎?

相關問題