您的位置:首页 > Web前端 > JavaScript

JavaScript搜索字符串并将搜索结果返回到字符串的方法

2015-04-06 16:41 567 查看

javascript操作字符串带有一个match方法用于搜索字符串,如果找到指定的字符串则返回搜索字符串,如果未找到则返回null,match方法区分大小写

<!DOCTYPE html>
<html>
<body>
<script>
var str="Hello world!";
document.write(str.match("world") + "<br>");
document.write(str.match("World") + "<br>");
document.write(str.match("worlld") + "<br>");
document.write(str.match("world!"));
</script>
</body>
</html>

返回结果:

world
null
null
world!

希望本文所述对大家的javascript程序设计有所帮助。

您可能感兴趣的文章:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息