我有一个包含多个类的元素列表,例如:
<input class="etape btn-info others">
<input class="etape btn-inverse others">
<input class="etape btn-danger others">
如何编写允许我执行以下操作的 jQuery 代码...
$(".etape").click(function(){
$(this).get("the class that starts with btn-")
// in order to store this value in a variable to reuse it later
});
最佳答案
您可以使用正则表达式或拆分
类名。
$(".etape").click(function(){
var classes = $.grep(this.className.split(" "), function(v, i){
return v.indexOf('btn') === 0;
}).join();
});
关于jquery - 如何获取以给定字符串开头的特定类的元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15505745/