在jQuery自动完成中获取价值 [英] Get value in jquery autocomplete

查看:80
本文介绍了在jQuery自动完成中获取价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码

jquery代码

$("input#shopName").autocomplete({
    source: "getShop.php",
    minLength: 2
});

从PHP返回的JSON值如下

The JSON value return from PHP as below

if(isset($_GET["term"])){

$query=$_GET["term"];
    $result = $dataset->get_custom_record("SELECT * FROM mc_shop WHERE shop_title like  '%" . $query . "%'  ORDER BY id");
}

 while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
        $row_array['id'] = $row['id'];
        $row_array['value'] =$row['shop_title'];

        array_push($return_arr,$row_array);
    }
echo json_encode($return_arr);

自动填充工作正常,但是从自动填充中选择值时,我需要在其中输入相应的 id值一个隐藏的变量,我不知道怎么办>

autocomplete is working fine but while selecting the value from autocomplete I need put the corresponding "id" value inside one hidden variable I don't know how to do>

推荐答案

$("input#shopName").autocomplete({
    source: "getShop.php",
    minLength: 2,
    select: function(event, ui) { 
        $("#theHidden").val(ui.item.id) 
    }
});

请参见 http://jqueryui.com/demos/autocomplete/#event-select

这篇关于在jQuery自动完成中获取价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆