如何从句子中删除HTML和CSS标记 [英] How to remove HTML and CSS tags from the sentence

查看:66
本文介绍了如何从句子中删除HTML和CSS标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个内容

i have this content

<p style="font-style: normal; font-variant: normal; line-height: 18px;"><span style="line-height: 34px; font-family: Georgia; font-size: 16px;"><img alt="" src="/Portals/0/Blog%20Images/00aaelevatoredu%20(1024x717).jpg" style="width: 400px; height: 220px; float: left; margin: 5px;" />Whether math problems, an English paper, or a science fair project, more and more teachers are asking students to utilize technology based programs to complete assignments, and students and parents are oftentimes unprepared to meet the new academic requirements. Many times there is an assumption that because kids have grown up with technology, they will automatically know how to use a variety of software programs, but this is often not the case. Kids may be adept at playing video games, using a tablet or cell phone, and working on a computer, but may not have the proficiency in word processing, presentation programs, cloud storage and management, and organizational programs necessary to help them achieve academically. There are many software programs that are crucial for kids to be successful in early elementary school, into college and beyond.</span></p>





所以我在这里如何删除html标签

plz帮帮我



我尝试过的事情:



我有尝试正则表达式使用javascript



So here how can i remove html tags here
plz help me

What I have tried:

I have tried regex using javascript

推荐答案

试试这个:



Try this:

var content = "<p>Dear sms,</p><p>This is a test notification for push message from center II.</p>";

var text =


(content).text();
(content).text();





或者尝试这个函数:





OR TRY this function:

function removeHTMLTags(){
	if(document.getElementById && document.getElementById("input-code")){
		var strInputCode = document.getElementById("input-code").innerHTML;
		/* 
			This line is optional, it replaces escaped brackets with real ones, 
			i.e. &lt; is replaced with < and &gt; is replaced with >
		*/	
		strInputCode = strInputCode.replace(/&(lt|gt);/g, function (strMatch, p1){
			return (p1 == "lt")? "<" : ">";
		});
		var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|


)/ g,);
alert(输入代码:\ n+ strInputCode +\ n\\\
Output text:\ n+ strTagStrippedText);
}
}
)/g, ""); alert("Input code:\n" + strInputCode + "\n\nOutput text:\n" + strTagStrippedText); } }


这篇关于如何从句子中删除HTML和CSS标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆