我的页面上有一个按钮,其中包含类comment_like和ID,comment_like_123456但最后的数字是可变的; 可能是1到1000000.
单击此按钮时,我需要获取结束编号,以便我可以在具有相同后缀的其他元素上运行任务.
有没有一种简单的方法可以在jQuery中获取这个数字?
$('.comment_like').click(function() {
var element_id = $(this).attr('id');
// grab number from element ID
// do stuff with that number
});
Run Code Online (Sandbox Code Playgroud) jquery ×1