本文介绍了使用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
推荐答案
<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替换字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!