【问题标题】:Unhandled Rejection (Error) when inserting a checkbox on React App在 React App 上插入复选框时未处理的拒绝(错误)
【发布时间】:2021-10-20 19:17:15
【问题描述】:

我正在尝试显示文本,然后在其后立即显示一个复选标记。但是,我收到错误“未处理的拒绝(错误):输入是一个空元素标签,既不能有children,也不能使用dangerouslySetInnerHTML。”

我知道它不应该有孩子,所以我也尝试将它移到 </li> 结束标记之前。我也尝试过这样做的想法:<input / >,因为我尝试在网上搜索答案。

更新: 将其更改为 <input / > 后,我现在收到错误:解析错误:预期对应的 JSX 结束标记为 .这是否意味着我必须添加一个结束标签并遇到与以前相同的问题?

我被难住了!任何帮助,将不胜感激。谢谢!

return (
 <div>
    <div>
        <table className = "className">
          <tbody>
          <tr>
            <th>Only avaliable Now</th>
          </tr>
              {this.state.time_array.map(item => (
                <tr>
                  <td>
                    <li><b> {item.id}</b> 
                        <input type="checkbox" 
                          id={item.Name}>
                          checked={item.gotIt}
                        </input>
                        <ul>
                           <li>Where to find: {item.find}</li>                      
                        </ul>
                    </li>
                </td>
              </tr>
              ))}
            </tbody>
        </table>
    </div>
  </div>      
);

【问题讨论】:

    标签: javascript html reactjs checkbox


    【解决方案1】:
    <input type="checkbox" 
       id={item.Name}>
       checked={item.gotIt}
    </input>
    

    代码上面的输入标签有一些错误的使用; 做如下改变;

    <input type="checkbox" 
       id={item.Name}>
       checked={item.gotIt}
    />
    

    <input type="checkbox" 
       id={item.Name}>
       checked={item.gotIt}
    >
    </input>
    

    【讨论】:

    • 不幸的是,我仍然遇到同样的错误。复选框的位置对您来说有什么特别之处吗?
    • 其实我有一个错字。现在我收到错误:解析错误: 需要相应的 JSX 结束标记您是否对此有任何想法?
    • id={item.Name}>, 最后一个字符 ">" 是多余的
    • 天啊,我完全错过了额外的“>”,并且正在寻找几个小时。非常感谢!!!!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-08
    • 2018-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-07
    • 1970-01-01
    相关资源
    最近更新 更多