在代码中我想要一个必需的属性来使该字段成为必填项。但它不起作用。有什么简单的方法可以对此验证使用react吗?
<label htmlFor="name">Name</label>
<input type="text" className="form-control"
id="name" placeholder="Enter name" required/>
最佳答案
尝试添加表单和按钮标签:
<form onSubmit={handler}>
<input type="text" id="name" placeholder="Enter name" required />
<button type="submit" />
</form
如果这不起作用,请尝试将 required
替换为 required="required"
关于reactjs - 如何将 required 属性添加到 react js 中的字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52902613/