function getCaption(url,parameter) { var index = url.lastIndexOf(parameter); url = url.substring(index+1,url.length); return url; } var url="http://www.baidu.com/123"; var a = getCaption(url,"/"); console.log(a,'aaa')