Firefox的innerHTML错误? [英] Firefox innerHTML Bug?

查看:129
本文介绍了Firefox的innerHTML错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一段简单的HTML

 < p id =skills>技巧< / p> 

在Firefox 3.6.3中,当我调用(带有JQuery)时:

  $(#skills)[0] .innerHTML =一些新文字


 < p id =skills> ;< a xmlns =http://www.w3.org/1999/xhtml>一些新的文字< / a>< / p> 



(注意,通过调用 $(#skills)。html(some new text)与JQuery发生同样的事情) b $ b

解决方案

原来,我的示例代码排除了实际问题的部分,这里是一个工作示例页面来显示问题。当您更改链接中的任何元素的HTML时,它将包装所有文本。 / 1999 / xhtml> THE TEXT< / a>



测试链接,它将取代技能内的html:

 < a xmlns =http:// www。 w3.org/1999/xhtml\">一些新的文字< / a> 

这可能不是一个错误,但似乎firefox是唯一的浏览器。

 < html> 
< head>
< script src =http://code.jquery.com/jquery-1.4.2.min.js>< / script>
< script type =text / javascript>
function test(){
$(#skills)[0] .innerHTML =一些新的文本
}
< / script>
< / head>
< body>
< a href =#onclick =test()>测试< / a>
< a href =http://google.com>
< p id =skills>技能< / p>
< / a>
< / body>
< / html>


I have a simple piece of HTML

<p id="skills">Skills</p>

in Firefox 3.6.3 when I call (with JQuery):

$("#skills")[0].innerHTML = "some new text"

Firefox renders it as

<p id="skills"><a xmlns="http://www.w3.org/1999/xhtml">some new text</a></p>

Where in the world is that link coming from??

(note the same thing happens by calling $("#skills").html("some new text") with JQuery)

解决方案

Turns out my sample code excluded the portion which is the actual problem, here is a working sample page to show the issue. When you change the html of any element within a link, it wraps all text with

<a xmlns="http://www.w3.org/1999/xhtml">THE TEXT</a>

In my demo when you click the "test" link, it will replace the html within skills with:

<a xmlns="http://www.w3.org/1999/xhtml">some new text</a>

This may not be a "bug", but it seems firefox is the only browser that does it.

<html>
  <head>
    <script src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
    <script type="text/javascript">
      function test() {
        $("#skills")[0].innerHTML = "some new text"
      }
    </script>
  </head>
  <body>
    <a href="#" onclick="test()">test</a>
    <a href="http://google.com">
      <p id="skills">Skills</p>
    </a>
  </body>
</html>

这篇关于Firefox的innerHTML错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆