jquery how to compare character string to end of other string

This question already has an answer here:

  • endsWith in JavaScript 29 answers

  • How about this?

    if(a.substr(a.length - b.length).toLowerCase() == b.toLowerCase()) {
        // b == last characters of a
    }
    

    If you need case sensitivity, just remove both .toLowerCase() methods.


    function endsWith(str, suffix) {
        return str.indexOf(suffix, str.length - suffix.length) !== -1;
    }
    
    链接地址: http://www.djcxy.com/p/83888.html

    上一篇: 从字符串JS中提取最后一个子字符串

    下一篇: jquery如何比较字符串到其他字符串的结尾