asp.net-mvc - 如何在 reactjs 中编写 onclick 事件?

标签 asp.net-mvc reactjs

这是我的代码 这是简单的形式。我想在按钮点击时调用点击事件

 render: function () {
            return (
                <form className="commentForm">
                    <input
                        type="text"
                        placeholder="Your name"
                        value={this.state.author}
                        onChange={this.handleAuthorChange}
                    />
                    <input
                        type="text"
                        placeholder="Say something..."
                        value={this.state.text}
                        onChange={this.handleTextChange}
                    />
                    <input type="submit" value="Post" />
                </form>
            );

最佳答案

您忘记为 form 传递 onSubmit 事件

 render: function () {
            return (
                <form className="commentForm" onSubmit={this.submit}>
                    <input
                        type="text"
                        placeholder="Your name"
                        value={this.state.author}
                        onChange={this.handleAuthorChange}
                    />
                    <input
                        type="text"
                        placeholder="Say something..."
                        value={this.state.text}
                        onChange={this.handleTextChange}
                    />
                    <input type="submit" value="Post" />
                </form>
            );


submit: function() {
// do your stuff
}

关于asp.net-mvc - 如何在 reactjs 中编写 onclick 事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50596424/

相关文章:

c# - 如何在播种过程中将 en 实体 ID 传递给另一个实体?

javascript - 语法错误 : C:/Users/J/metafields-for-shopify/src/SettingsForm. js : Unexpected token, 预期,(18:1)

javascript - 我必须按两次按钮才能从 firebase 实时数据库填充 react 状态

node.js - AWS API网关WebSocket API : how to use it with React/NodeJS/native WebSocket?

c# - MasterPage 上的 ASP.Net MVC 身份验证检查

javascript - 添加到序列化数组中的复杂对象在服务器端始终为空

asp.net-mvc - ASP.NET MVC 单元测试 - 虚假存储库变得笨拙

c# - 自定义 Api 授权忽略 AllowAnonymous

javascript - mapStateToProps 从 reducer 返回未定义的状态

reactjs - 传递给 withAuthenticator HOC 的封闭组件的 props 为空