第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

單擊時(shí)自動完成更新第二個(gè)輸入框上的相同值

單擊時(shí)自動完成更新第二個(gè)輸入框上的相同值

qq_遁去的一_1 2023-05-11 16:02:22
請有人幫我解決這個(gè)問題,因?yàn)榇蠖鄶?shù)事情看起來都不錯(cuò),比如從數(shù)據(jù)庫中獲取匹配結(jié)果,但是當(dāng)我在兩個(gè)輸入框中單擊值時(shí),會添加相同的自動完成值。有人可以幫我解決這個(gè)問題嗎?這是我的 html:<div class="col-sm-12">    <label class="form-label-outside">From</label>        <div class="form-wrap form-wrap-inline">        <input id="from-input" class="form-input" name="from" type="text">        <div id="from-show-list" class="list-group"></div>    </div></div><div class="col-sm-12">    <label class="form-label-outside">To</label>    <div class="form-wrap form-wrap-inline">        <input id="to-input" class="form-input"  name="to" type="text">        <div id="to-show-list" class="list-group"></div>    </div></div>我的 js<script src="js/jquery.min.js"></script><script>    $(document).ready(function() {        $("#from-input").keyup(function() {            let searchText = $(this).val();            if (searchText != "") {                $.ajax({                    url: "airports.php",                    method: "post",                    data: {                        query: searchText,                    },                    success: function(response) {                        $("#from-show-list").html(response);                    },                });            } else {                $("#from-show-list").html("");            }        });        // Set searched text in input field on click of search button        $(document).on("click", "a", function() {            $("#from-input").val($(this).text());            $("#from-show-list").html("");        });    });
查看完整描述

1 回答

?
SMILET

TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超4個(gè)贊

問題出現(xiàn)是由于鏈接上的點(diǎn)擊功能。通過指定包含這些鏈接的 div 的 ID 來定義兩個(gè)單獨(dú)的鏈接組。


    // Set searched text in input field on click of search button

    $(document).on("click", "#from-show-list a", function() {

        $("#from-input").val($(this).text());

        $("#from-show-list").html("");

    });


    // Set searched text in input field on click of search button

    $(document).on("click", "#to-show-list a", function() {

        $("#to-input").val($(this).text());

        $("#to-show-list").html("");

    });

像這樣使用 css 將最大高度應(yīng)用于結(jié)果 div。


<div id="from-show-list" class="list-group" style="max-height: 100px;  overflow: auto;"></div>

<div id="to-show-list" class="list-group" style="max-height: 100px;  overflow: auto;"></div>



查看完整回答
反對 回復(fù) 2023-05-11
  • 1 回答
  • 0 關(guān)注
  • 162 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號