![](/img/trans.png)
[英]How to toggle class when user selects a list item coming from api in react.s?
[英]Don't close the modal when click on content with React.s
我創建了一個簡單的react modal,但是當我單擊modal內容時,它也會關閉它。
我有一個包裝類div與類modal_wrapper
,當模式打開時,當我單擊此div模式中的任何位置關閉時,它都會更改主體的背景。
但是,當我單擊modal_content
div的任何位置時,模態也會關閉。
當我在modal_content
div中單擊時,如何停止關閉模態?
您需要停止單擊事件傳播。 在dont_close_modal函數中,捕獲click事件,然后您可以像這樣停止傳播。
dont_close_modal:function(e) {
e.stopPropagation()
this.setState({
open_modal:true
})
},
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.