如何在JavaScript中检查字符串是否包含子字符串?
jQuerysearch()方法用于检查字符串是否包含JavaScript中的子字符串。
您可以尝试运行以下代码,以检查字符串“Nhooo:FreeVideoTutorial”在JavaScript中是否包含子字符串“point”:
<html>
<head>
<title>JavaScript String search() Method</title>
</head>
<body>
<script>
var re = "point";
var str = "Nhooo: Free Video Tutorials";
if ( str.search(re) == -1 ) {
document.write("Does not contain Point" );
} else {
document.write("包含点!" );
}
</script>
</body>
</html>