使用javascript替换字符串 [英] replacing string using javascript

查看:70
本文介绍了使用javascript替换字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

< STRONG style ="COLOR:red"> a</STRONG> dvertising
我想要输出广告
我怎么能用字符串替换方法替换我尝试过的方法,但是它不能正常工作

<STRONG style="COLOR: red">a</STRONG>dvertising
I want output advertising
how can i replace i tried with string replace method but it is not working fine

推荐答案

Ok Sam,

即使您不断重复发布相同的问题,我也会为您提供答案.我什至会帮助您处理上一个请求中的大写部分.您怎么可能忘记了这件事?

Ok Sam,

eventhough you keep on re-posting the same question over and over again I''ll help you with an answer. I''ll even go sofar as to help you with the capitalization part you had in one of your last requests. How could that have happend that you forgot about that?

<html>
	<head>
		<title>Test</title>
		</head>
	<body>
	<script type="text/javascript">
		function capitalizeFirstLetter(string) 
		{ 
			return string.charAt(0).toUpperCase() + string.slice(1); 
		} 

		var highLightedString = "<STRONG style=\"COLOR: red\">a</STRONG>dvertising";
		var strippedTags = highLightedString.replace(/<[^>]*>/g, "");
		
		document.write(capitalizeFirstLetter(strippedTags));
	</script>
	</body>
</html>



文件正文中的输出:广告"

如果仍然有问题,请回到此问题进行讨论.我不想再看到这样的转贴.


问候,

曼弗雷德(Manfred)



Output in document body: "Advertising"

And if you still have questions, come back to this question to discuss about it. I don''t want to see yet another repost of this.


Regards,

Manfred


这篇关于使用javascript替换字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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