Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JQuery how to.find()不区分大小写?_Jquery - Fatal编程技术网

JQuery how to.find()不区分大小写?

JQuery how to.find()不区分大小写?,jquery,Jquery,我只想打印出名称中包含字符串“bc”的制造商的名称 这是我迄今为止的尝试 <Manufacturers> <Manufacturer name="abc"> <flags=""/> </Manufacturer><Manufacturer name="abcd"> <flags=""/> </Manufacturer> <Manufacturer name="abcde"&g

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

这是我迄今为止的尝试

<Manufacturers>
  <Manufacturer name="abc">
    <flags=""/>
  </Manufacturer><Manufacturer name="abcd">
    <flags=""/>
  </Manufacturer>
  <Manufacturer name="abcde">
    <flags=""/>
  </Manufacturer>
<Manufacturers>
$(“#自动完成”)。关于(“FilterableBeforFilter”,函数(e,数据){
var$ul=$(本);
html=“”;
$ul.html(“
  • ”); $ul.列表视图(“刷新”); $.ajax({ 键入:“获取”, url:“./Sources.xml”, 数据类型:“xml”, 错误:函数(jqXHR、textStatus、errorshown){ log('Error:'+errorshown); }, 成功:函数(xml.toLowerCase()){ log('AJAX请求成功'); $(xml).find('Manufacturer[name*=”'+$(data.input.val()+''']')).each(function(){ console.log($(this.attr('name')); }); $ul.html(html); $ul.列表视图(“刷新”); $ul.trigger(“updatelayout”); } }); });

    问题是.find()区分大小写。我如何做相同但不区分大小写的操作,而不是将您的支票构建到您的查找中,您应该匹配“Manufacturer”,然后按制造商名称搜索,并且查询在函数中都转换为小写

          $( "#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");
                    }
                });
    
        });
    

    我建议如下:

    $(xml).find("Manufacturer").each(function(i){
      console.log($(this)[0].attributes.name.value.toLowerCase().indexOf(query.toLowerCase()) >= 0;
    })
    
    
    
    根据,
    children()
    函数区分大小写,因此您可以改用它():

    var xml='',
    $results=$(xml).children('Manufacturer[name*=”'+$(data.input.val()+'']');
    $(“#result”).append(“#results=”+$results.length);
    
    在本例中,您必须使用“filter”函数:我确实偶然发现了该函数,但我不知道如何在上面的代码示例中实现它。它不会通过.find(),因为这是我遇到的区分大小写的问题,在本例中,$(xml)返回了什么?更新了我的答案。我使用了一个伪造的xml返回,所以它可能不完全正确,但这就是要点。实现了这一点,但它只适用于它们完全匹配的情况。我需要它的工作,如果“制造商”包含的问题更新了我的答案,去试试吧。它正在检查查询是否是制造商名称中的子字符串。所以“玩具”在“丰田”上是真的
    “Toyota.toLowerCase().indexOf(“toY.toLowerCase())>=0
    返回
    true
    我认为“大小写不敏感”只处理xml对象名,而不处理属性。。。
    var xml = '<Manufacturers><Manufacturer name="abc"><flags=""/></Manufacturer><Manufacturer name="abcd"><flags=""/></Manufacturer><Manufacturer name="abcde"><flags=""/></Manufacturer><Manufacturers>';
    
    // we create a jQuery objecct from the xml string (above),
    // find all the Manufacturer elements,
    // filter those elements using the filter() method:
    var bcInName = $(xml).find('Manufacturer').filter(function() {
      // keeping only those elements in which the lower-cased 'name'
      // attribute contains the string 'bc':
      return this.attributes["name"].value.toLowerCase().indexOf('bc') > -1;
    // using map() to create a map:
    }).map(function() {
      // consisting of the value of the name attribute from the
      // elements that we kept in the collection:
      return this.attributes["name"].value;
    // using get() to convert the map to an array:
    }).get();
    
    // using this to write a log in the 'result' pane of
    // of the snippet:
    snippet.log(bcInName);
    
    // logging to the console:
    console.log(bcInName);
    
    var xml = '<Manufacturers><Manufacturer name="abc"><flags=""/></Manufacturer><Manufacturer name="abcd"><flags=""/></Manufacturer><Manufacturer name="abcde"><flags=""/></Manufacturer></Manufacturers>',
      $results = $( xml ).children( 'Manufacturer[name*="' + $(data.input).val() + '"]' );
    
    $( "#result" ).append( '# results = ' + $results.length );