Javascript 提交后清除文本区域

Javascript 提交后清除文本区域,javascript,forms,textarea,reactjs,Javascript,Forms,Textarea,Reactjs,我在天窗对话框中有以下表单组件,提交后,如果重新打开包含表单的对话框,它将包含以前提交的值。有人能告诉我如何停止此操作并在每次打开对话框时清除textarea值吗 以下是我的组件: var AddNoteForm = React.createClass({ componentDidMount: function() { React.findDOMNode(this.refs.notes).value = ""; }, handleSubmit: function (even

我在天窗对话框中有以下表单组件,提交后,如果重新打开包含表单的对话框,它将包含以前提交的值。有人能告诉我如何停止此操作并在每次打开对话框时清除textarea值吗

以下是我的组件:

var AddNoteForm = React.createClass({


componentDidMount: function() {

        React.findDOMNode(this.refs.notes).value = "";
},
handleSubmit: function (event) {
    event.preventDefault();

    var notes = React.findDOMNode(this.refs.notes).value;

    var details = {
        studentId: this.props.studentId,
        schoolId: this.props.schoolId,
        notes: notes
    };

    this.props.onSubmit(details);
},

render: function() {
    return (
        <form className="pure-form pure-form-aligned"
            onSubmit={this.handleSubmit}>
            <div className="pure-control-group">
                <label htmlFor="notes">Note</label>
                <textarea ref="notes" id="notes" placeholder="Note..." >
                </textarea>

            </div>
            <div className="pure-controls">
                <input type="submit" value="Save" />
            </div>
        </form>
    );
}
});

module.exports = AddNoteForm;
var AddNoteForm=React.createClass({
componentDidMount:function(){
React.findDOMNode(this.refs.notes).value=“”;
},
handleSubmit:函数(事件){
event.preventDefault();
var notes=React.findDOMNode(this.refs.notes).value;
变量详细信息={
studentId:this.props.studentId,
学校ID:this.props.schoolId,
附注:附注
};
this.props.onSubmit(细节);
},
render:function(){
返回(
注
);
}
});
module.exports=AddNoteForm;

基本上您的表单没有卸载。因此,在componentDidMount中编写代码是没有意义的。因此,解决问题的快速方法是在读取handlesubmit方法中的值后清除textarea框

handleSubmit: function (event) {
  event.preventDefault();

  var notes = this.refs.notes;

  var details = {
    studentId: this.props.studentId,
    schoolId: this.props.schoolId,
    notes: notes.value
  };

  notes.value = ""; // Unset the value
  this.props.onSubmit(details);
},

所以如果有人陷入了这个问题, 我使用的是非受控组件,清除它有点复杂, 我只是换成了受控的,然后得到了:)


谢谢你的回复。我已经试过了,但是对话的价值仍然存在,有什么想法吗?
<form onSubmit={e => this.handleSubmit(e)}>
<textarea value={this.state.text} onChange={ e => this.handleChange(e) } />
<button>Submit Comment</button>
</form>
  handleSubmit = event => {
  event.preventDefault();    
  this.setState({ text: '' });
  };