选择器类可以是:
c-1
c-2
c-3
(etc...)选择器也可以有其他类,下面是一个可能的HTML示例:
<div class="foo c-2 foofoo"></div>我想知道c之后的号码。在这种情况下-我去找2。
我怎么能这么做?
发布于 2013-09-15 09:29:05
试一试
var el = $('.c-2')//get the element whose class value has to be extracted
var val = el.attr('class').match(/\bc-(\d+)\b/)[1]发布于 2013-09-15 09:36:02
如果您确信您的类中没有其他整数存在
试一试
var s ="foo c-2 foofoo";
var result = /\d+(?:\.\d+)?/.exec(s);
alert(result); //2 is the resultFiddle
https://stackoverflow.com/questions/18810836
复制相似问题