如何将jQuery对象数组转换为HTML字符串

WNR*_*erg 5 javascript jquery

在jQuery Infinite Carousel中,它.clone()用来做无限的效果.除非它克隆的代码具有HTML5元素,否则这很有用.IE7和IE8无法将HTML5元素特定的CSS规则应用于克隆或以后页面加载插入的元素.

innerShiv JavaScript的插件插入的方式,IE7和IE8将呈现只是适当的CSS精细的元素.

问题是innerShiv将HTML字符串作为参数,但jQuery .clone()方法返回一个jQuery对象数组.

为了将两者结合使用,我需要将.clone()的输出转换为innerShiv能够解析的HTML字符串.

有关如何做到这一点的任何想法?

Bra*_*tie 8

HTML:

<p class="foo"><canvas class="bar"></canvas></p>
Run Code Online (Sandbox Code Playgroud)

JavaScript:[ 参考 ]

// grab the object, with HTML 5 element(s).
var p = $('p');

// clone it
var c = p.clone();

// grab the inner html (wrap it so we can get the HTML)
var html = $('<div>').append(c).html();

// alert us of the contents
alert(html);
Run Code Online (Sandbox Code Playgroud)

演示:

http://jsfiddle.net/bradchristie/tDFYn/