我正在为一个网站编写一个用于Firefox(Greasemonkey),Opera和Chrome的浏览器插件。问题是,当我将document.innerHTML
加载到变量中时,
<form name="foo" action="foo.php" method="get">
<td id="td">text:
<input name="k" type="text" />
</td>
</form>
...网站上面的原始代码(我正在编写插件)转换为
<form name="foo" action="foo.php" method="get">
<td id="td">text:
**<input name="k" type="text">**
</td>
......这个。如您所见,自动关闭<input />
标记不再关闭,</form>
标记也消失了。我几乎所有的网络都搜索过,但我读过的解决方案都没有解决我的问题。
答案 0 :(得分:4)
获取</form>
时,我会在Firefox中显示结束.innerHTML
标记。
我建议丢失的标签是由于你的标记,我很确定无效:
<!-- A <form> wrapping a <td> ? -->
<form name="foo" action="foo.php" method="get">
<td id="td">text:
<input name="k" type="text" />
</td>
</form>
<td>
元素的父级应为<tr>
,而不是<form>
。
鉴于此标记:
<table>
<tr>
<form name="foo" action="foo.php" method="get">
<td id="td">text:
<input name="k" type="text" />
</td>
</form>
</tr>
</table>
... Firefox为innerHTML
提供了<table>
:
<tbody>
<tr>
<form name="foo" action="foo.php" method="get"></form>
<td id="td">text:
<input name="k" type="text">
</td>
</tr>
</tbody>
尝试更正无效标记。
答案 1 :(得分:0)
好吧,看看你的代码,你需要在中间创建一个带有未闭合TD的表单。
<form name="foo" action="foo.php" method="get">
<td id="td"><span>text:<input name="k" type="text" /></span></td>
</form>
试试这种方式。