首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JQUERY在一个文本函数上自动完成,该函数接受html形式的其他文本的输入。

JQUERY在一个文本函数上自动完成,该函数接受html形式的其他文本的输入。
EN

Stack Overflow用户
提问于 2020-08-29 00:52:25
回答 1查看 40关注 0票数 0

您好,我想从一个输入字段中读取一个文本值,然后在JQUERY函数中使用它从数据库中获取数据。我想要像这样填充源: /search/batch_name_by_barnID/1,但输出类似于: /batch_name_by_barnID?term=1

如何设置此部分:源:"/search/batch_name_by_barnID/"+$('#barn_id').text(),以获取类似/search/batch_name_by_barnID/{number}的输出,而不是/search/batch_name_by_barnID?term=1

我的HTML是:

代码语言:javascript
复制
    <input type="text" class="form-control search_occupied_barn_name" placeholder="Type here ..." name="barn_name">
      <span class="help-block search_occupied_barn_name_empty" style="display: none;">No Results Found ...</span>
      <input type="text" class="search_barn_id" name="barn_id" id="barn_id">
      <label>باتش</label><br>
      <input type="text" class="form-control search_batch_name_barn" placeholder="Type here ..." name="BatchName">
      <span class="help-block search_batch_name_barn_empty" style="display: none;">No Results Found ...</span>
      <input type="text" class="search_batch_id" name="batch_id" id="batch_id">

我的JQUERY是:

代码语言:javascript
复制
 $( ".search_batch_name_barn" ).autocomplete({
       source: "/search/batch_name_by_barnID/"+$('#barn_id').text(),
       minLength: 1,
       response: function(event, ui) {
             if (ui.content.length === 0) {

                 $(this).parent().addClass('has-error');
                 $(this).next().removeClass('glyphicon-ok').addClass('glyphicon-remove');
                 $(".search_batch_name_barn_empty").show();
                 $('.form_submit').hide();

             } else {
                 $(".search_batch_name_barn_empty").hide();
                 $('.form_submit').show();
             }
         },
       select: function(event, ui) {
         $('.search_batch_id').val(ui.item.id);
         $('.search_batch_name_barn').val(ui.item.value);
         }
     });
代码语言:javascript
复制
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-08-30 04:25:02

我找出了问题所在:我添加了一个按钮,然后使用搜索方法代码default.js从该按钮触发了"search_batch_name_barn“的自动完成

代码语言:javascript
复制
  $("#getBatch").click(function () {
     alert("test");
     $(".search_batch_name_barn").show();
     $(".search_batch_name_barn").autocomplete('search');
  });

HTML

代码语言:javascript
复制
      <input type="text" class="form-control search_occupied_barn_name" placeholder="Type here ..." name="barn_name">
      <span class="help-block search_occupied_barn_name_empty" style="display: none;">No Results Found ...</span>
      <input type="hidden" class="search_barn_id" name="barn_id" id="barn_idorg">
      <button type="button" class="btn btn-primary" name ="getBatch" id="getBatch">Get Batch</button>
      <label>باتش</label><br>
      <input type="text" class="form-control search_batch_name_barn" placeholder="Type here ..." name="BatchName">
      <span class="help-block search_batch_name_barn_empty" style="display: none;">No Results Found ...</span>
      <input type="hidden" class="search_batch_id" name="batch_id" id="batch_id">
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63637972

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档