通过jquery清理<font>等标签,保留文本

数据库内有 <font><p><span>等包含各种html标签的信息,而且每个<FONT>标签有不同的样式属性, < font align="center" style="color:red">hello world </font> 等等。 我现在需要 font 的align 属性 的值 center 换掉 justify , 如果font 没有 align 属性就删除掉<font>标签保留他的内容hello world . 只显示hello world字符就可以,不要显示font 的样式。

第1个回答  2011-09-19
大概是这样吧:
<script>
$("font").each(function (i) {
if($(this).attr("align") =='center'){
$(this).attr("align","justify");
} else if($(this).attr("align") == undefined) {
$(this).contents().unwrap();
}
});
</script>本回答被网友采纳
第2个回答  2011-09-19
如果要清理所有的html标签就比较复杂了
相似回答