这是我的代码
@H_301_2@jquery代码
$("input#shopName").autocomplete({ source: "getShop.PHP",minLength: 2 });@H_301_2@从PHP返回的JSON值如下所示
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);@H_301_2@自动完成工作正常,但在从自动完成中选择值时,我需要将相应的“id”值放在一个隐藏变量中,我不知道该怎么做>
解决方法
$("input#shopName").autocomplete({ source: "getShop.PHP",minLength: 2,select: function(event,ui) { $("#theHidden").val(ui.item.id) } });@H_301_2@见http://jqueryui.com/demos/autocomplete/#event-select