laravel在一个页面中实现两个脚本

时间:2017-12-22 08:06:06

标签: javascript php jquery html laravel

由于我使用脚本进行自动完成输入,问题是其中一个工作而另一个不起作用,所以我该如何解决这个问题呢?

<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>

1 个答案:

答案 0 :(得分:0)

问题是使用var path两次wrong 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>