当我将脚本用于自动完成输入时,问题是其中一个起作用而另一个不起作用,那么如何解决此问题?

<input class="ventypeahead form-control"  type="text" placeholder="category">

<script type="text/javascript">
  var path = "{{ route('autocompletecategory') }}";
  $('input.cattypeahead').typeahead({
    source:  function (query, process) {
      return $.get(path, { query: query }, function (data) {
        return process(data);
      });
    }
  });
</script>

<input class="cattypeahead form-control"  type="text" >

<script type="text/javascript">
  var path = "{{ route('autocompletevendor') }}";
  $('input.ventypeahead').typeahead({
    source:  function (query, process) {
      return $.get(path, { query: query }, function (data) {
        return process(data);
      });
    }
  });
</script>

最佳答案

问题是使用两次var pathwrong class in wrong placeusing input in wrong place

只需反转类名并更改变量名,

 <input class="ventypeahead form-control"  type="text" placeholder="category">

  <script type="text/javascript">
  var path1 = "{{ route('autocompletecategory') }}";
   $('input.ventypeahead').typeahead({
    source:  function (query, process) {
    return $.get(path1, { query: query }, function (data) {
            return process(data);
        });
      }
     });
 </script>

 <input class="cattypeahead form-control"  type="text" >

 <script type="text/javascript">
  var path2 = "{{ route('autocompletevendor') }}";
  $('input.cattypeahead').typeahead({
    source:  function (query, process) {
    return $.get(path2, { query: query }, function (data) {
            return process(data);
        });
       }
     });
  </script>

09-16 12:11