Javascript 输入 Reactjs 需要相应的 JSX 结束标记

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30852751/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 05:50:30  来源:igfitidea点击:

Expected corresponding JSX closing tag for input Reactjs

javascriptreactjsreactjs-fluxreact-jsx

提问by Sajin M Aboobakkar

While creating a component in Reactjs with input fields error occurs Error: Parse Error: Line 47: Expected corresponding JSX closing tag for input at http://localhost/chat-react/src/script.js:47:20 </div>

在 Reactjs 中使用输入字段创建组件时发生错误 Error: Parse Error: Line 47: Expected corresponding JSX closing tag for input at http://localhost/chat-react/src/script.js:47:20 </div>

var Main = React.createClass({
    render: function() {
        return (
            <div className="card-action">
                <i class="mdi-action-account-circle prefix"></i>
                <input id="icon_prefix" type="text" class="validate">
            </div>
        );
    }
});

回答by Crob

You need to close the input element with a />at the end.

您需要/>在末尾使用 a 关闭输入元素。

<input id="icon_prefix" type="text" class="validate" />

回答by Deke

This error also happens if you have got the order of your components wrong.

如果您的组件顺序错误,也会发生此错误。

Example: this wrong:

例子:这个错误:

 <ComponentA> 
    <ComponentB> 

    </ComponentA> 
 </ComponentB> 

correct way:

正确方法:

  <ComponentA> 
    <ComponentB>

    </ComponentB>  
  </ComponentA> 

回答by gaurav rathor

You have to close all tags like , etc for this to not show.

您必须关闭所有标签,如 , 等才能不显示。

回答by Yuvraj Patil

It happens when we do not close a html tag.

当我们不关闭 html 标签时会发生这种情况。

Make sure all the html tags are closed.

确保所有 html 标签都已关闭。

In my case it was the <br>tag. It should be <br />.

就我而言,它是<br>标签。应该是<br />

Try temporarily removing piece of code until you found which html tag closing is missing.

尝试暂时删除一段代码,直到您发现缺少哪个 html 标签关闭。

回答by Eugen Sunic

All tags must have enclosing tags. In my case, the hrand inputelements weren't closed properly.

所有标签都必须有封闭标签。就我而言,hrinput元素没有正确关闭。

Parent Error was: JSX element 'div' has no corresponding closing tag, due to code below:

父错误是:JSX 元素“div”没有相应的结束标记,由于以下代码:

<hr class="my-4">
<input
  type="password"
  id="inputPassword"
  class="form-control"
  placeholder="Password"
  required
 >

Fix:

使固定:

<hr class="my-4"/>
<input
 type="password"
 id="inputPassword"
 class="form-control"
 placeholder="Password"
 required
/>

The parent elements will show errors due to child element errors. Therefore, start investigating from most inner elements up to the parent ones.

由于子元素错误,父元素将显示错误。因此,开始从大多数内部元素到父元素进行调查。