jQuery / Get numbers from a string

前端 未结 8 2174
北海茫月
北海茫月 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:45

    In your click handler:

    var number = $(this).attr('id').split('_').pop();
    
    0 讨论(0)
  • 2020-12-14 14:46

    This is a task for plain-old regular expressions, it has nothing to do with jQuery:

    "comment_like_123456".match(/\d+/)
    
    => ["123456"]
    
    0 讨论(0)
提交回复
热议问题