Jquery 寻找以

Jquery 寻找以,jquery,Jquery,我试图从我的XML中查找以文本“EPCF”开头的唯一子级 以下是我今天的代码: $(xml).find('Cat[name="' + catname + '"]').children("EPCF_1_1").each(function() { 这确实只返回EPCF_1_1 我的问题是如何返回以EPCF开头的内容 我试过了 $(xml).find('Cat[name="' + catname + '"]').children().filter(':contains(EPCF)').each(fu

我试图从我的XML中查找以文本“EPCF”开头的唯一子级

以下是我今天的代码:

$(xml).find('Cat[name="' + catname + '"]').children("EPCF_1_1").each(function() {
这确实只返回EPCF_1_1

我的问题是如何返回以EPCF开头的内容

我试过了

$(xml).find('Cat[name="' + catname + '"]').children().filter(':contains(EPCF)').each(function() {
没有运气

$(xml).find('Cat[name="' + catname + '"]').children().filter(':contains("EPCF")').each(function() {
同样没有运气-也没有返回错误。


您需要提取每个XML子节点的内容,并测试它是否以EPCF开始:

epcfNodes = $(xml).find('Cat[name="' + catname + '"]')
                  .children()
                  .filter(function(i, v){
                      return /^EPCF/.test($(v).contents()[0].data);
                  });

这就是实现这一点的技巧-工作结果:$(xml).find('Cat[name=“”+catname+”)).children('[name^=“EPCF”]')。each(function(){
epcfNodes = $(xml).find('Cat[name="' + catname + '"]')
                  .children()
                  .filter(function(i, v){
                      return /^EPCF/.test($(v).contents()[0].data);
                  });