HTML:收到警告 - 标签位置无效(输入)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4814969/
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-29 06:23:13  来源:igfitidea点击:

HTML : Getting warning - Invalid location of tag (input)

htmlxhtml

提问by Bibhaw

I have simple form and placed it inside the < div id="center">. It's working fine but still getting warning. why so ?

我有一个简单的表单并将其放在< div id="center"> 内。它工作正常,但仍然收到警告。为什么这样 ?

e.g. < div id="center">

例如 <div id="center">

<div id = "center">

   <form action="test" method="post">

    <input type="hidden" id="text1" name="texts"/> </input>  --> getting warning

   </form>    </div>

Thanks in advance.

提前致谢。

回答by Quentin

An <input>element cannot be a child element of <form>. A block element needs to go there.

一个<input>元素不能是一个子元素<form>。一个块元素需要去那里。

You need something like form --> fieldset --> inputor form --> div --> input.

你需要类似form --> fieldset --> input或的东西form --> div --> input

You also have a self-closing <input />followed by an end tag </input>which doesn't have an open input to close.

您还有一个自关闭,<input />后跟一个结束标记</input>,它没有要关闭的打开输入。

回答by keatch

You have already closed the input tag

您已经关闭了输入标签

<input type="hidden" id="text1" name="texts"/>

Written in this form is a self-closing tag. There is no need to close it in explicit form. Plus input must be inside a block container. Check the example here http://www.w3.org/TR/1999/REC-html401-19991224/interact/forms.html#h-17.4

用这种形式写的是一个自闭合标签。无需以显式形式关闭它。Plus 输入必须在块容器内。检查这里的例子http://www.w3.org/TR/1999/REC-html401-19991224/interact/forms.html#h-17.4

回答by JesseBoyd

by putting the <input type="text" ... />within a <div>block like this makes the error go away in eclipse or spring tool suite. following is a very basic example.

通过将 放在这样<input type="text" ... /><div>块中,可以使 eclipse 或 spring 工具套件中的错误消失。下面是一个非常基本的例子。

<div>
    username:<input type="text" name="user" />
</div>