问题描述
我正在尝试使用浏览器DOM API的cloneNode()方法克隆HTML节点,甚至使用Jquery clone()函数。 API与HTML标签完美配合,但我在使用HTML5标签时遇到了一些问题,例如
I am trying to clone an HTML node using cloneNode() method of browser's DOM API and even using Jquery clone() function. The API works perfectly fine with HTML tags, However i am facing some issues while using it with HTML5 tags like time e.g.
问题在于 < time>
标记内容< time class =storydate> 2010年4月7日< / time>
转换为:< :time class = storydate awpUniq =912> 2010年4月7日。虽然IE正确呈现原始时间节点,但为什么克隆API存在这样的问题。
The issue is that following <time>
tag content <time class="storydate">April 7, 2010</time>
gets converted to: <:time class=storydate awpUniq="912">April 7, 2010. Although IE renders the original time node correctly then why such issue with the clone API.
在FF / chrome中没有观察到这个问题。请提供一些线索如何避免这种情况
And this issue isn't observed in FF/ chrome. Please give some clue how to avoid this
推荐答案
这有什么帮助吗?来自HTML5 Shiv问题列表:
Is this of any help? From the HTML5 Shiv issue list:
链接到
解决方案似乎是:
// 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?
这篇关于IE中的HTML5节点的cloneNode问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!