因为需要除去来自后台数据的样式及标签,总结了两种简单的方法:
第一种:
html: <div class="announcementText">${(item.content)!''}</div> js: /** *ClearCourseAnnounceDiv() *去除课程公告的html **/ function ClearCourseAnnounceDiv(){ var AnnounceDom = $(".announcementText"); AnnounceDom.each(function(index){ var DText = $(this).html(); var Dvalue = DText.replace(/</?[^>]*>/g,""); $(this).text(Dvalue); }); }
第二种:
html: <div class='text-css'>${(item.content)!''}</div> js: /** *ClearCourseAnnounceDiv() *去除课程模块上描述的html **/ function ClearCourseAnnounceDiv(){ var AnnounceDom = $(".text-css"); var DText = '', Dvalue =''; AnnounceDom.each(function(){ DText = $(this).html();
Dvalue = $('<p>'+DText+'</p>').text();
$(this).text(Dvalue); }); }