为了账号安全,请及时绑定邮箱和手机立即绑定

form表单提交数据时,keywords会替换掉之前原有的参数?

form表单提交数据时,keywords会替换掉之前原有的参数?

开满天机 2018-07-23 21:54:07
如题:这样的情况怎么解决好呢?,然道写一个提交前处理keywords再拼接上去的方法?代码:<form acceptCharset="gbk" method="get" action="https:xxx_search.htm?product=true&tags=123" >                 <div className="searchBar">                   <input className="searchVal" placeholder="输入关键词搜索"                    value={this.state.value} name="keywords"                     onChange={event => {                       this.setState({                         value: event.target.value,                       });                     }} />                  <button className="searchBtn" type="submit">搜索</button>                 </div>               </form>
查看完整描述

2 回答

?
潇湘沐

TA贡献1816条经验 获得超6个赞

<form action="https:xxx_search.htm">
    <input type="hidden" name="product" value="true"/>
    <input type="hidden" name="tags" value="123"/>
    <input className="searchVal" placeholder="输入关键词搜索" 
                  value={this.state.value} name="keywords"
                    onChange={event => {
                      this.setState({
                        value: event.target.value,
                      });
                    }} /></form>


查看完整回答
反对 回复 2018-07-29
?
当年话下

TA贡献1890条经验 获得超9个赞

不用form表单的默认提交,用fetch或者axios异步提交

search(){    const {value} = this.state;
    fetch(`https:xxx_search.htm?product=true&tags=123&keywords=${value}`).then(...)
}
render(){    // ...
     <div className="searchBar">
        <input
            className="searchVal"
            placeholder="输入关键词搜索" 
            value={this.state.value} name="keywords"
            onChange={event => {                this.setState({                    value: event.target.value,
                });
            }} />
        <button className="searchBtn" onClick={this.search}>搜索</button>
    </div>
}


查看完整回答
反对 回复 2018-07-29
  • 2 回答
  • 0 关注
  • 830 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信