猿问

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

您好,我想从一个输入字段读取文本值,然后在 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);

         }

     });


狐的传说
浏览 125回答 1
1回答

catspeake

我找出了问题所在:我添加了一个按钮,然后使用搜索方法代码从该按钮触发了“search_batch_name_barn”的自动完成:default.js&nbsp; $("#getBatch").click(function () {&nbsp; &nbsp; &nbsp;alert("test");&nbsp; &nbsp; &nbsp;$(".search_batch_name_barn").show();&nbsp; &nbsp; &nbsp;$(".search_batch_name_barn").autocomplete('search');&nbsp; });超文本标记语言&nbsp; &nbsp; &nbsp; <input type="text" class="form-control search_occupied_barn_name" placeholder="Type here ..." name="barn_name">&nbsp; &nbsp; &nbsp; <span class="help-block search_occupied_barn_name_empty" style="display: none;">No Results Found ...</span>&nbsp; &nbsp; &nbsp; <input type="hidden" class="search_barn_id" name="barn_id" id="barn_idorg">&nbsp; &nbsp; &nbsp; <button type="button" class="btn btn-primary" name ="getBatch" id="getBatch">Get Batch</button>&nbsp; &nbsp; &nbsp; <label>باتش</label><br>&nbsp; &nbsp; &nbsp; <input type="text" class="form-control search_batch_name_barn" placeholder="Type here ..." name="BatchName">&nbsp; &nbsp; &nbsp; <span class="help-block search_batch_name_barn_empty" style="display: none;">No Results Found ...</span>&nbsp; &nbsp; &nbsp; <input type="hidden" class="search_batch_id" name="batch_id" id="batch_id">
随时随地看视频慕课网APP
我要回答