reactjs - 按钮 onclick 在 reactJS 中不起作用,代码如下
问题描述
const [open, setIsOpen] = useState(false);
const openForm = () => setIsOpen(true);
<button class="openButton" onClick={() => {openForm}} style={openButton}>Chat</button>
<div class="chatPopup" id="myForm" style={chatPopup}>
<Form open={open}/>
<div class="formContainer" style={formContainer}>
<span class="title1" style={title1}>Chat</span>
<label for="msg"><b>Message</b></label>
<iframe customFrameSection style={customFrameSection} frameborder="1" id="AIChat" style={{border:'1px solid rgba(0,255,0,0.3)',width: "285px",height: "400px"}}></iframe>
<button type="button" class="btn cancel" onclick={closeForm} style={cancelButton}>Close</button>
</div>
</div>
我已经尝试了多种方法,点击应该打开聊天窗口,如何打开带有 id myform 的聊天弹出窗口,缺少在任何地方提供 myform id,请指点我,这里做错了什么。
解决方案
您正在向 onClick 侦听器提供匿名函数,它什么都不做,要么在那里调用 clickForm 函数,要么在 onClick 中传递它的引用,比如 -
const [open, setIsOpen] = useState(false);
const openForm = () => setIsOpen(true);
<button class="openButton" onClick={openForm} style={openButton}>Chat</button>
推荐阅读
- soapui - 将 SOAPUI 中的查询参数定义为变量
- javascript - 如何在javascript中的函数内使用循环
- r - 在 ggplot2 R 中绘制年度比较和时间分布
- java - Spring数据jdbc拼写
- css - 如何使用 CSS 更改某个面包屑元素的颜色?
- go - #cgo LDFLAGS 中的标志无效
- python - TypeError:字符串索引必须是整数,同时尝试将 json 转换为 csv
- r - 在合并r中的两列时合并两个数据表
- python - 当我们知道值和它所在的列时,如何在数据框中找到行?
- windows - 使用 SetFilePointer 更改扇区写入位置不起作用?