当包含表单时,html 段落标签在 Firefox 中自动关闭
我在 Firefox 中偶然发现了一个奇怪的行为。我有一个动态创建的文本,在其中插入了一个包含链接的表单元素,以便能够通过 post 方法传递参数。理想情况下,它应该与文本一起流动并且看起来像普通的锚点。 然而,虽然它在 IE 中正常显示,但 Firefox 会在表单之前终止该段落,从而插入不需要的换行符。 有谁知道为什么会发生这种情况并有解决方法/替代解决方案?
IE 中的结果 (ok):
<p class="article" >This is my paragraph and here goes my
<form style="display: inline" name="link_form" action="link.html" method="post">
<input type="hidden" name="lnk_id" value="1" /><a class="link" href="#" onclick="link_form.submit()">link</a></form>**</p>**
Firefox 中的结果 (ko):
<p class="article" >This is my paragraph and here goes my**</p>**
<form style="display: inline" name="link_form" action="link.html" method="post">
<input type="hidden" name="lnk_id" value="1" /><a class="link" href="#" onclick="link_form.submit()">link</a></form>
提前致谢
I stumbled across a strange behavior in Firefox. I have a dynamically created text, into which I have inserted a form element including a link in order to be able to pass parameters via the post method. Ideally, it should just flow with the text and look like a normal anchor.
However, whereas it displays normally in IE, Firefox terminates the paragraph just before the form, which inserts an undesired line break.
Does anyone have an idea why this happens and have a workaround / alternative solution ?
Result in IE (ok):
<p class="article" >This is my paragraph and here goes my
<form style="display: inline" name="link_form" action="link.html" method="post">
<input type="hidden" name="lnk_id" value="1" /><a class="link" href="#" onclick="link_form.submit()">link</a></form>**</p>**
Result in Firefox (ko):
<p class="article" >This is my paragraph and here goes my**</p>**
<form style="display: inline" name="link_form" action="link.html" method="post">
<input type="hidden" name="lnk_id" value="1" /><a class="link" href="#" onclick="link_form.submit()">link</a></form>
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是完全正常的,P 标签只能包含内联元素,而表单则不然。 (参见http://www.w3.org/TR/html401 /struct/text.html#h-9.3)
由于 HTML4 规范不允许您关闭标签,Firefox 会假设您忘记在表单开始之前关闭 P 标签,因此您可以在以下位置看到结束标签例如,使用 Firebug 检查 DOM。
It's perfectly normal, a P tag can only contain inline elements, which is not the case of a form. (see http://www.w3.org/TR/html401/struct/text.html#h-9.3)
Since HTML4 specs allow you not to close the tags, Firefox assumes you forgot to close your P tag before the beginning of your form, hence the closing tag you can see when inspecting the DOM with Firebug, for example.