(相關(guān)資料圖)
本教程操作環(huán)境:Windows10系統(tǒng)、react18版、Dell G3電腦。
react怎么禁止默認(rèn)事件?
React:阻止默認(rèn)事件
在html頁(yè)面中直接通過return false即可阻止默認(rèn)事件
<a href="#" onclick="alert("阻止跳轉(zhuǎn)");return false">點(diǎn)擊</a>而在react中需要使用e.preventDefault()
function PreventDe(){ return ( <a href="#" onClick={(e)=>{ console.log("阻止跳轉(zhuǎn)"); e.preventDefault() }}>點(diǎn)擊</a> )}export default PreventDe事件三要素:事件源,事件,事件處理函數(shù)
推薦學(xué)習(xí):《react視頻教程》
以上就是react怎么禁止默認(rèn)事件的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注php中文網(wǎng)其它相關(guān)文章!
關(guān)鍵詞: React