首页 > 代码库 > 除去子节点的样式及html标签

除去子节点的样式及html标签

因为需要除去来自后台数据的样式及标签,总结了两种简单的方法:

 第一种:

 

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 = http://www.mamicode.com/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 = http://www.mamicode.com/$(‘

‘+DText+‘

‘).text();
               $(this).text(Dvalue); }); }

 

除去子节点的样式及html标签