为了账号安全,请及时绑定邮箱和手机立即绑定

JQUERY 自动完成文本函数,该函数从 html 形式的其他文本获取输入

JQUERY 自动完成文本函数,该函数从 html 形式的其他文本获取输入

PHP
狐的传说 2023-11-04 20:51:38
您好,我想从一个输入字段读取文本值,然后在 JQUERY 函数中使用它从数据库获取数据我希望像这样填充源:/search/batch_name_by_barnID/1,但输出类似于:/batch_name_by_barnID?项=1我如何设置这部分:source: "/search/batch_name_by_barnID/"+$('#barn_id').text(),以获得像 /search/batch_name_by_barnID/{number} 而不是 /search/batch_name_by_barnID?term 的输出? =1我的 HTML 是:    <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 是: $( ".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);         }     });
查看完整描述

1 回答

?
catspeake

TA贡献1111条经验 获得超0个赞

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


  $("#getBatch").click(function () {

     alert("test");

     $(".search_batch_name_barn").show();

     $(".search_batch_name_barn").autocomplete('search');

  });

超文本标记语言


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


查看完整回答
反对 回复 2023-11-04
  • 1 回答
  • 0 关注
  • 72 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信