jQuery / Get numbers from a string

前端 未结 8 2213
北海茫月
北海茫月 2020-12-14 14:11

I have a button on my page with a class of comment_like and an ID like comment_like_123456 but the numbers at the end are variable; could be 1 to 1

8条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-14 14:27

    http://jsfiddle.net/hj2nJ/

    var x = 'comment_like_6846511';
    var y = '';
    
    for (i = 0; i < x.length; i++)
    {
        if ("" + parseInt(x[i]) != "NaN") //if the character is a number
            y = y + x[i];
    }
    
    document.write(y);
    

提交回复
热议问题