对于常见的搜索需求业务场景,用户输入完成后,点击enter事件请求数据,要求不提交页面,实现数据局部更新,这需要用到react中的表单Forms。

处理方法:

(1)html书写

form标签中去掉action参数,定义onSubmit方法,如下所示:

<div className="mc2">
      <form onSubmit={(e) => this.getSearchData(e,this.state.searchkey)}>
        <b></b>
        <input name="searchkey" type="text" className="search" placeholder="请输入关键字" value={this.state.searchkey} onChange={(e) => this.change(e.target.name,e.target.value)}/>
      </form>
</div>

 

(2)事件处理

关键的是阻止掉页面默认提交:

getSearchData(event,name) {
    //ajax处理
    event.preventDefault();//阻止页面提交刷新<br>}

 

 

连接:

http://www.cnblogs.com/sunLemon/p/9089911.html

https://www.imooc.com/learn/1012

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-18
  • 2022-12-23
  • 2021-11-23
  • 2021-07-09
猜你喜欢
  • 2022-12-23
  • 2021-09-22
  • 2022-12-23
  • 2021-07-02
  • 2022-12-23
  • 2021-05-17
  • 2021-11-03
相关资源
相似解决方案