找到某个班级并将其归还

时间:2022-02-01 19:41:42

How can I see if an element as a class that consists of only numbers and return its value, ignoring other classes?

如何将元素视为仅包含数字的类并返回其值,而忽略其他类?

<div class="some_identifier some_other_class 1548"></div>

So running it on the above HTML would return 1548

因此,在上面的HTML上运行它将返回1548

2 个解决方案

#1


6  

$('div').attr('class').match(/\b\d+\b/)[0]

http://jsfiddle.net/rtPa6/

#2


0  

Try with:

var div = $('<div class="some_identifier some_other_class 1548"></div>');

div.attr('class').match(/\S\d+\S/);

#1


6  

$('div').attr('class').match(/\b\d+\b/)[0]

http://jsfiddle.net/rtPa6/

#2


0  

Try with:

var div = $('<div class="some_identifier some_other_class 1548"></div>');

div.attr('class').match(/\S\d+\S/);