reactjs - 为什么我的 React js 按钮 onMouseDown 不起作用?
问题描述
<div className="commentinputMain">
<img
className="commentinputPic"
src={PF + user.profilePic}
alt="Profile Pic"
/>
<input
className="commentinputInputMain"
placeholder="Share something!"
onMouseDown={displayButtons}
onChange={(e) => {
setText(e.target.value);
setShowButtons(true);
}} />
</div>
<div className="commentinputMain">
{showButtons && (
<>
<p>
<button onMouseDown={console.log("Wait WHAT??")}>Cancel</button>
</p>
<button>Post</button>
</>
)}
</div>
<hr className="commentinputh1" />
为什么单击时取消不起作用?请给我一个解决方案。我正在使用 React JS 并正在创建一个博客网站。
编辑:一旦我将控制台日志替换为此,它就对我有用
onMouseDown={()=>console.log("Wait WHAT??")}
真是个愚蠢的问题,对不起,它有一个非常直截了当的答案
解决方案
你不能像这样调用console.log 试试这样让我知道这是否有效
onMouseDown={()=>console.log("Wait WHAT??")}
推荐阅读
- bazel - Tensorflow Hub 从源代码构建失败
- gnuplot - 负值后 gnuplot 崩溃
- c# - 取消在用户控制下运行的任务
- sql - SQL 查询 - 使用替换功能很慢
- node.js - .npmrc 配置文件未读取环境变量以下载私有节点模块
- python - 如何修复 PyCharm 中的“sdl2 - ImportError: DLL load failed”错误
- abap - 下载使用 CL_XLSX_DOCUMENT 类构建的 Excel 文档
- wordpress - 如何使子菜单项始终打开?
- sequelize.js - 如果未提供查询,Sequelize 删除“where”?
- ruby-on-rails - rails:图片不会出现在heroku上,但可以在本地使用