我下载了一个CSS文件,如下所示(前几行)
[class^="flaticon-"]:before, [class*=" flaticon-"]:before,
[class^="flaticon-"]:after, [class*=" flaticon-"]:after {
font-family: Flaticon;
font-size: 20px;
font-style: normal;
margin-left: 20px;
}
.flaticon-3dm-file-format:before {
content: "\f100";
}问题是并不是所有的文件扩展名类都是以相同的方式编写的。
.flaticon-3gp-file-format-variant:before {
content: "\f103";
}例如,一个类如下所示
$(myelement).addClass('flaticon-' + extension + '-file-format');因此,这行代码只在某些时候有效。
有没有办法在jQuery中找到并添加包含flaticon和extension-type的特定类?
发布于 2016-10-26 15:03:35
CSS选择器中使用的任何东西也可以与Jquery选择器一起使用。
所以你需要做的就是
$('[class^="flaticon-"][class*="-file-format"]')[class^="flaticon-"] ->使用flaticon-[class*="-file-format"] ->选择类以(^)开头的所有元素在名称中选择类以-file-format anywhere (*)开头的所有元素
因此,当您将它们组合在一起时,这意味着选择一个元素,该元素的类以flaticon-开头,后面的任何位置都有-file-format。
因此这将使用class选择这两个元素
.flaticon-3dm-file-format和flaticon-3gp-file-format-variant
https://stackoverflow.com/questions/40255700
复制相似问题