我有一段简单的 HTML
<p id="skills">Skills</p>
在 Firefox 3.6.3 中,当我调用(使用 JQuery)时:
$("#skills")[0].innerHTML = "some new text"
Firefox 将其呈现为
<p id="skills"><a xmlns="http://www.w3.org/1999/xhtml">some new text</a></p>
这个链接到底是从哪里来的?
(请注意,使用 JQuery 调用 $("#skills").html("some new text")
也会发生同样的事情)
最佳答案
这不是 Firefox 中的错误,您会获得额外的 <a></a>
首先...我会禁用您的所有插件,然后重试,您安装的某些特定内容会干扰这里。
我假设您正在使用 Firebug 查看此内容,您上面给出的确切示例(页面中没有其他内容)是否执行相同的操作?您可以在这里尝试演示:http://jsfiddle.net/Wcjk9/
更新:
您的示例确实在 Firefox 中显示了一些奇怪的行为,但是它是“允许”执行此操作的。由于 HTML 无效,浏览器可以而且确实在这里给出了一些奇怪的行为。浏览器中的解析器/脚本引擎可以自由地假设您拥有有效的 HTML,例如唯一 ID。如果您的 HTML 无效,那么...它不承担任何责任。我必须包括 this quote :
On two occasions I have been asked, 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.
忽略jsbin添加的错误,you can see the problem here (第一个验证错误)。 anchor 内不允许有 block 元素。如果您替换 <p>
,您可以拥有内联元素。在您的示例中带有 <span>
你将拥有有效的 HTML...并且这种奇怪的行为就会消失:)
关于jquery - Firefox 内部 HTML 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2940826/