首页 > 解决方案 > 为什么我的 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??")}

真是个愚蠢的问题,对不起,它有一个非常直截了当的答案

标签: reactjsbuttonclickpls

解决方案


你不能像这样调用console.log 试试这样让我知道这是否有效

onMouseDown={()=>console.log("Wait WHAT??")}

推荐阅读