doukuanghuan7582 2017-03-29 16:53
浏览 71

jQuery自动完成具有相同ID的多个输入

I want to implement this autocomplete to my page: http://www.bewebdeveloper.com/tutorial-about-autocomplete-using-php-mysql-and-jquery and it works but in my case I use clone() function to copy all <li> elements like here: http://jsfiddle.net/x42c3anw When I have several inputs autocomplete works only for first input, how I can edit this function? :

function autocomplet() {
var min_length = 0; // min caracters to display the autocomplete
var keyword = $('#country_id').val();
if (keyword.length >= min_length) {
    $.ajax({
        url: 'ajax_refresh.php',
        type: 'POST',
        data: {keyword:keyword},
        success:function(data){
            $('#country_list_id').show();
            $('#country_list_id').html(data);
        }
    });
} else {
    $('#country_list_id').hide();
}
}
// set_item : this function will be executed when we select an item
function set_item(item) {
// change input value
$('#country_id').val(item);
// hide proposition list
$('#country_list_id').hide();
}

I undurstand this is because ID is not uniqe, is there possibility to add some increment to id or use class? If yes how I can do that?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥35 平滑拟合曲线该如何生成
    • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
    • ¥15 名为“Product”的列已属于此 DataTable
    • ¥15 安卓adb backup备份应用数据失败
    • ¥15 eclipse运行项目时遇到的问题
    • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
    • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
    • ¥15 自己瞎改改,结果现在又运行不了了
    • ¥15 链式存储应该如何解决
    • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站