我想從onclick事件傳遞「this」到一個函數,而不是傳遞給另一個函數,它的第一個函數工作,但「this」沒有傳遞到從第一個函數調用的下一個函數?如何將onclick事件傳遞給多個函數?
這是我的代碼,請指教?
function hideProcessing(nextThis) {
nextThis.parentNode.parentNode.style.display = "none";
nextThis.parentNode.style.display = "block";
}
function showProcessing(param) {
param.parentNode.parentNode.style.display = "block";
param.parentNode.style.display = "none";
var thisElement = this
setTimeout('hideProcessing(thisElement)', 3000);
}
<div>
<span id="overlap">show me</span>
<div id="sendContainer" class="sendContainer">
<button onclick="showProcessing(this);">send</button>
</div>
</div>
你有這個存儲在參數中。你分配thisElement = this時出錯了。你也不應該用string來調用setTimeout,應該有一個函數作爲第一個參數。在這個函數中,你仍然可以訪問'param',這是你的。 –
試試這個.name或者那樣的id。 https://stackoverflow.com/questions/4195970/what-does-this-mean – zod