在IE8及以下版本中,Jquery AutoComplete无效?

时间:2014-05-26 06:30:56

标签: jquery ruby-on-rails internet-explorer

jQuery JavaScript Library v1.4.1 + Rails 4.0.0

我在我的项目中的两个地方使用jquery自动完成,它在google crome和mozilla中正常工作但是当我使用它进入ie 8时,自动完成本身无法正常运行错误就在这一行

var matcher = new RegExp( "^" +   $.ui.autocomplete.escapeRegex( request.term.trim() ), "i" ); // Error is here...

<script>
    function get_city_names(name, id, cities){
      div_name = "#" + name;
      div_id = "#" + id;
         $(div_name).autocomplete({
            autoFocus: true,
            delay: 0,
            minLength: 1,
            max: 5,
            scroll: true,
            source:  function(request, response) {
              var matcher = new RegExp( "^" +   $.ui.autocomplete.escapeRegex( request.term.trim() ), "i" );
              response( $.grep(cities, function( item ){
                  return matcher.test(item.name);
              }) );
            },
            // Select - If you  select any item it'll give the values (ID) and label
            select: function(event, ui) {
              $(div_name).val(ui.item.name); // Label display
              $(div_id).val(ui.item.id); // Assign ID with respect city.
              return false;
            },
            close: function() {
              origin_name = $('#origin_name').val().toUpperCase();
              destination_name = $('#destination_name').val().toUpperCase();
               $.grep(cities, function( city ){
                  cityInCapitals = city.name.toUpperCase();
                  if (cityInCapitals == origin_name.trim() && div_name == "#origin_name" && origin_name != ''){
                    $(div_name).val(city.name);
                    $(div_id).val(city.id);
                    return false;
                  }
                  else if (cityInCapitals == destination_name.trim() && div_name == "#destination_name" && destination_name != ''){
                    $(div_name).val(city.name);
                    $(div_id).val(city.id);
                    return false;
                  }
                  else{
                    return false;
                  }
              });
            },
          }).data( "ui-autocomplete" )._renderItem = function(ul, item) {
            return $("<li>")
              .append( "<a>" + item.name + "</a>" )
              .appendTo(ul);
          };

    }
</script>

错误对象不支持此属性或方法行34,即&#34; var matcher = new RegExp(&#34; ^&#34; + $ .ui.autocomplete.escapeRegex(request.term) .trim()),&#34; i&#34;);&#34;

0 个答案:

没有答案