Get the last occurrence of string within another string
This question already has an answer here:
就像是
var check = "project",
url = "/home/doc/some-user-project/project";
if (url.substr(-check.length) == check){
// it ends with it..
}
Try this
<script>
var url = "/home/doc/some-user-project/project";
url.match(/project$/);
</script>
The response is a array with project, if the responde is 'null' because it is not found
链接地址: http://www.djcxy.com/p/83892.html上一篇: JavaScript或jQuery字符串以效用函数结束
下一篇: 获取另一个字符串中最后一次出现的字符串