日期:2014-05-18 浏览次数:20472 次
<div id="msg">
我是文本1
<p>标签1</p>
我是文本2
<div>标签2</div>
<h3>H3
<em>哈哈</em>
</h3>
我是文本3
</div>
<input type="button" id="btnRemoveText" value="删除文本" />
<script src="js/jquery-1.4.2.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
$('#btnRemoveText').click(function() {
var html = $('#msg').children(); //保存div的所有子元素,但不包括文本
$('#msg').html(html); //先清空再把原来的html标签加入
});
});
</script>