1 回答

TA貢獻1836條經驗 獲得超3個贊
似乎您沒有使用 聲明任何變量var,const或者let這可能是您遇到問題的地方。
通過this作為參數傳遞,您可以訪問span您正在懸停的確切位置。在這個解決方案中,您可以更改其中任何一個的文本span,甚至添加更多內容,這仍然有效。
setInterval(function() {
const number = Math.floor((Math.random() * 100) + 1);
document.getElementById("in02").innerHTML = number
}, 5000);
function titlep(elem) {
const aVal = document.getElementById('in02').textContent;
const elemVal = elem.textContent.replace(/[^0-9]/g, '');
elem.title = Number(aVal) * Number(elemVal);
}
<div style="cursor: pointer">
<span class="tp-cu-po" onmouseover="titlep(this)">4+ </span><br>
<span class="tp-cu-po" onmouseover="titlep(this)">3+ </span><br>
<span class="tp-cu-po" onmouseover="titlep(this)">2+ </span><br>
<span class="tp-cu-po" onmouseover="titlep(this)">1+ </span><br>
</div><br> A =
<a id="in02"></a>
添加回答
舉報