简体   繁体   English

如何调试:在React中从div更改为form元素。 没有反应

[英]How to debug: Change from div to form element in React. No response

I try to change from div to form element (to use the type="submit" ) in the react render but there's no response. 我尝试在react渲染中从div更改为form元素(使用type="submit" ),但是没有响应。 It shows http://localhost:3000/ ? 它显示http://localhost:3000/ ? FYI, div is working fine. 仅供参考, div工作正常。 The code is as below: 代码如下:

<div className="SearchBar">
 <input placeholder="Enter A Song, Album, or Artist" onChange={this.handleTermChange} />
 <a onClick={this.handleSearch}>SEARCH</a>
</div>

===

<form className="SearchBar" onSubmit={this.handleSearch}>
 <input placeholder="Enter A Song, Album, or Artist"  onChange={this.handleTermChange} />
 <button type="submit">SEARCH</button>
</form>

The Github repo is here . Github仓库在这里

Thank you for your time. 感谢您的时间。

Probably your submit is giving refresh on the screen. 您的提交可能正在屏幕上刷新。

Use an e.preventDefault () at the beginning of your function its handleSearch function 在函数的开头使用e.preventDefault()及其handleSearch函数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM