日期:2014-05-16 浏览次数:20382 次
<!DOCTYPE html >
<html>
<head>
<meta charset="UTF-8">
<title>replace</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$('#r').click(function(){
$('*').each(function(){
if(this.tagName=='SPAN'){
var t = $(this).html();
var c = $(this).attr('class');
var a = new Array();
a = c.split(' ');
var classhide = '' ;
$.each(a,function(index,callback){
classhide+=a[index]+"-- ";
})
$(this).replaceWith(' <span class="'+classhide+'"> '+t+' </span> ');
}
});
alert(id1.outerHTML)
})
});
</script>
</head>
<body>
<div id='id1' style="width: 600px; height: 300px;">
<span class="blue bolder">
Hi <i>Hello</i>
<span class="underline red"> And </span>
<b>Goodbye</b>
</span>
<span class="oblique green"> How Are You </span>
</div>
<button id="r">click</button> <br />
</body>
</html>
<style type="text/css">
.blue{color: blue; }
.green{color: green; }
.red{color: red; }
.oblique{font-style: oblique;}
.bolder{font-style: bolder;}
.underline{text-decoration:underline}
.hidden{visibility:hidden;}
.visible{visibility:visible;}
</style>
<!DOCTYPE html >
<html>
<head>
<meta charset="UTF-8">
<title>replace</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript">