Вы надеваете» Для этого нужен JQuery.
function endsWith(s,c){
if(typeof s === "undefined") return false;
if(typeof c === "undefined") return false;
if(c.length === 0) return true;
if(s.length === 0) return false;
return (s.slice(-1) === c);
}
endsWith('test','/'); //false
endsWith('test',''); // true
endsWith('test/','/'); //true
Вы также можете написать прототип
String.prototype.endsWith = function(pattern) {
if(typeof pattern === "undefined") return false;
if(pattern.length === 0) return true;
if(this.length === 0) return false;
return (this.slice(-1) === pattern);
};
"test/".endsWith('/'); //true
Jquery не может сделать это. Однако JavaScript может. –
Возможный дубликат [как получить последний символ строки?] (Http://stackoverflow.com/questions/3884632/how-to-get-the-last-character-of-a-string) –