jQuery的,HTML5,追加()/ appendTo()和IE [英] jQuery, html5, append()/appendTo() and IE

查看:216
本文介绍了jQuery的,HTML5,追加()/ appendTo()和IE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  1. 创建HTML5页面。

  1. Create an html5 page.

请确保你从remysharp.com/2009/01/07/html5-enabling-script/补充,使IE浏览器会发现标签的脚本。

Make sure you have the script from remysharp.com/2009/01/07/html5-enabling-script/ added so that IE will notice the tags.

创建硬codeD <节ID ='什么'>< /段> 标签

Create an hardcoded <section id='anything'></section> tag.

使用jQuery 1.3.2,追加另一个部分标记: $('#什么')追加(&lt;节ID =无所谓&GT;&LT; /节&gt; ); 到目前为止,一切工作在所有浏览器

Using jQuery 1.3.2, append another section tag: $('#anything').append('<section id="whatever"></section>'); So far, everything works in all the browsers.

重复previous一步。 $('#不管')追加(&lt;节ID =失败&GT;&LT; /段&gt;'); 这是IE6 / 7失败。火狐/ Safari会继续工作。

Repeat the previous step. $('#whatever').append('<section id="fail"></section>'); This is where IE6/7 fails. Firefox/Safari will continue working.

Error


  • 这可能是IE6 / 7不能处理HTML5部分标记。我这样说是因为当我更改步骤4,&lt;节&GT; &LT; D​​IV&GT; ,IE6 / 7将开始工作。

  • It could be that IE6/7 can't handle the HTML5 section tag. I say this because when I change step 4 from <section> to <div>, IE6/7 will start working.

如果我用使用document.createElement()和创建我的新元素,它的工作原理,但似乎jQuery的追加() 与HTML5元素的一个问题。

If I use document.createElement() and create my new element, it works, but it seems like jQuery's append() has a problem with html5 elements.

推荐答案

该缺陷是在IE的实现的innerHTML的 - 由于某种原因,它不喜欢通过的innerHTML插入未知的元素 - 而DOM脚本是罚款。

The bug is in IE's implementation of innerHTML - for some reason it doesn't like the "unknown" elements being inserted via innerHTML - whereas DOM scripting is fine.

jQuery使用创建控股DIV,然后滴在你想通过innerHTML来追加的标记。 IE现在看到的未知元素作为两个新的破元素,即&lt;物品&gt;内容&LT; /条&GT; 被视为文章 #text /条,引起的innerHTML borking。

jQuery uses creates a holding div, and then drops in the markup you want to append in via innerHTML. IE now sees the unknown elements as two new broken elements, i.e. <article>content</article> is seen as ARTICLE, #text, /ARTICLE, caused by innerHTML borking.

下面是一个例子,看看在IE中,你会发现innerHTML的插入方法错误地报告插入DIV 3个节点:的 http://jsbin.com/olizu

Here's an example, check it out in IE and you'll see that innerHTML insertion method incorrectly reports 3 nodes inserted in the div: http://jsbin.com/olizu

对于那些没有IE浏览器截图: http://leftlogic.litmusapp.com/pub/2c3ea3e

Screenshot for those without IE: http://leftlogic.litmusapp.com/pub/2c3ea3e

这篇关于jQuery的,HTML5,追加()/ appendTo()和IE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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