2011-08-12 28 views

回答

4
<script> 
var styles; 
$("style").each(function(a,b){ 
    styles = styles + "\n" + b.html(); 
    $(this).remove(); 
}); 

$("#style").html('<style>'+ styles +'</style>'); 

</script> 
<div id="style> 

</div> 
+1

什么是a,b? :D –

+0

@LeahSilber:a =索引(0,1,2,3,4),b是内容 – genesis

1

这里是你如何能在两行做到这一点:

// add a new style element before the first one with all the rules 
$('style:first').before('<style type="text/css" id="new">'+$('style').text()+'</style>'); 

// remove all the style elements except the one added above 
$("style:not('#new')").remove(); 

Here is a demo更新