gpt4 book ai didi

JQuery 如何 .find() 不区分大小写?

转载 作者:行者123 更新时间:2023-12-03 22:50:52 25 4
gpt4 key购买 nike

<Manufacturers>
<Manufacturer name="abc">
<flags=""/>
</Manufacturer><Manufacturer name="abcd">
<flags=""/>
</Manufacturer>
<Manufacturer name="abcde">
<flags=""/>
</Manufacturer>
<Manufacturers>

我想只打印名称中包含字符串“bc”的制造商的名称

这是我迄今为止的尝试

      $( "#autocomplete" ).on( "filterablebeforefilter", function ( e, data ) {
var $ul = $(this);
html = "";
$ul.html( "<li><div class='ui-loader'><span class='ui-icon ui-icon-loading'></span></div></li>" );
$ul.listview( "refresh" );
$.ajax({
type: "GET",
url: "./Sources.xml",
datatype: "xml",
error: function(jqXHR, textStatus, errorThrown) {
console.log('Error: ' + errorThrown);
},
success: function(xml.toLowerCase()) {
console.log('AJAX Request is succeded.');

$(xml).find('Manufacturer[name*="' + $(data.input).val() + '"]').each(function(){
console.log($(this).attr('name'));
});
$ul.html(html);
$ul.listview( "refresh" );
$ul.trigger( "updatelayout");
}
});

});

问题是 .find() 区分大小写。我怎样才能做同样的事情但不区分大小写

最佳答案

您应该匹配“Manufacturer”,然后按制造商名称进行搜索,并且查询在函数中都转换为小写,而不是在查找中构建检查

$(xml).find("Manufacturer").each(function(i){
console.log($(this)[0].attributes.name.value.toLowerCase().indexOf(query.toLowerCase()) >= 0;
})

关于JQuery 如何 .find() 不区分大小写?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31104941/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com