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