当包含表单时,html段落标记在firefox中自动关闭

时间:2011-03-15 13:39:54

标签: html firefox forms tags paragraph

我在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>

提前致谢

1 个答案:

答案 0 :(得分:5)

这是完全正常的,P标签只能包含内联元素,而不是表单的情况。 (见http://www.w3.org/TR/html401/struct/text.html#h-9.3

由于HTML4规范允许您不关闭标记,因此Firefox假定您忘记在表单开头之前关闭P标记,因此在使用Firebug检查DOM时可以看到结束标记。