在IE中使用HTML5节点的cloneNode问题

时间:2011-08-19 13:15:24

标签: html5

我正在尝试使用浏览器DOM API的cloneNode()方法克隆HTML节点,甚至使用Jquery clone()函数。 API与HTML标签完美配合,但是我在使用HTML5标签时遇到了一些问题,例如时间。

问题是,以下<time>标记内容<time class="storydate">April 7, 2010</time>会转换为:&lt;:time class = storydate awpUniq =“912”&gt; 2010年4月7日。虽然IE呈现原始时间节点正确的为什么克隆API有这样的问题。

在FF / chrome中没有观察到这个问题。请提供一些线索如何避免这个

1 个答案:

答案 0 :(得分:3)

这有什么帮助吗?来自HTML5 Shiv问题列表:

http://code.google.com/p/html5shiv/issues/detail?id=28

链接

http://pastie.org/935834#49

解决方案似乎是:

// Issue: <HTML5_elements> become <:HTML5_elements> when element is cloneNode'd
// Solution: use an alternate cloneNode function, the default is broken and should not be used in IE anyway (for example: it should not clone events)

// Example of HTML5-safe element cloning
function html5_cloneNode(element) {
  var div = html5_createElement('div'); // create a HTML5-safe element

  div.innerHTML = element.outerHTML; // set HTML5-safe element's innerHTML as input element's outerHTML

  return div.firstChild; // return HTML5-safe element's first child, which is an outerHTML clone of the input element
} // critique: function could be written more cross-browser friendly?