这里我在一个元素中有3个类,即sfCol_20 tsfCol_100 msfCol_100
。我想得到类sfCol_{digit}
的值,但是后面的逻辑返回3个值。如何解决这个问题?
var matchedClass = $('div').attr('class').match(/sfCol_[0-9]+/g);
console.log(matchedClass);
var re = new RegExp("sfCol_[0-9]+", "g");
if ($('div').attr('class').match(re)) {
matchedClass = $('div').attr('class').match(re).join(" ");
console.log(matchedClass);
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="sfCol_20 tsfCol_100 msfCol_100">
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
</div>
&#13;