【问题标题】:Cannot add link and label inside an input element in reactjs无法在reactjs的输入元素内添加链接和标签
【发布时间】:2023-04-03 10:11:01
【问题描述】:

我需要在 reactjs 组件中添加一个链接和标签 inside 输入元素。以下是我所拥有的:

render() {
  return(
    <div className="login-panel-page">
      <input type="password" id="password"
             name="password" value="" placeholder="Password" maxLength="255" autoCapitalize="off">
        <label htmlFor="password">Password</label>
        <a>Show password</a>
      </input>
    </div>
  )
}

但这是我得到的:

bundle.js:9179 Uncaught 
Error: input is a void element tag 
and must neitherhave `children` nor use `dangerouslySetInnerHTML`. 
Check the render method of Login.

谁能帮助我实现这一目标?

【问题讨论】:

标签: reactjs


【解决方案1】:

输入不能有子,你可以这样做

参考:https://github.com/facebook/react/issues/6241

 render() {
    return (
    <div className="login-panel-page">
                    <input type="password" id="password" name="password" value="" placeholder="Password" maxLength="255" autoCapitalize="off"/>
                    <label htmlFor="password">Password</label>
                    <a href="#">Show password</a>

    </div>
    )

【讨论】:

    猜你喜欢
    • 2023-01-20
    • 1970-01-01
    • 1970-01-01
    • 2012-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-23
    • 1970-01-01
    相关资源
    最近更新 更多