很难让JS使用each和this进行迭代

Having trouble getting JS to iterate using each and this

本文关键字:this 迭代 each JS 使用 很难      更新时间:2023-09-26

我试图从文件列表中识别mp3文件并操纵它们,但即使我使用"this",我的代码也会删除所有"b.type",即使它不匹配regex

//MP3 TIME
$('.secure .content li.file b.type').each(function() {  
    var fileType = $(this).text();
    if(/[MP3]/.test(fileType) == true){
        $(this).remove();//just to see if it works
    }   
});

任何帮助都太棒了!由于

您的正则表达式不正确,目前它匹配包含M, p或3的所有文件类型。相反,尝试:

/mp3/i

匹配所有包含"mp3"的文件类型

i标志使其不区分大小写,因此它将匹配mp3, mp3等