如何在单击时将自动完成jQuery UI的元素移动到输入类型文本中


how can I move the element at auto complete jQuery-UI into input type text when clicked

我尝试使用jQuery UI将自动完成时的文本移动到输入类型文本中。我只需要点击自动完成的文本并将其移动到输入中。

insert.php

<!DOCTYPE html>
<html>
<head>
 <title> Home Page </title>
 <link rel='stylesheet' type='text/css' href='style.css'>
 <link rel="stylesheet" type="text/css" href="css/bootstrap.css"> 
 <link rel="stylesheet" href="jqueryui.css">
</head>
<body>
<?php
echo"
 <form id='form1' enctype='multipart/form-data' action='simpanpage.php' method='post'>
  Label : <input type=text name=label id=label> <input type=submit value=save>
 </form> 
";
?>
<script>
$( "#label" ).autocomplete({
 source: "searchlabel.php",
 minlength: 1,
 select: function( event, ui ) {
   log( ui.item ?
   "Selected Label: " + ui.item.value :
   "Nothing selected, input was " + this.value );
 }
});
</script>
</body>
</html> 

searchlabel.php

<?php 
include 'koneks.php';     
$dba = new database;
$dba->connectMYSQL(); 
$arr = array();
if(isset($_GET['term']))
{
    $term = $_GET['term'];
    $query2 = "SELECT label FROM pages WHERE label LIKE '%$term%'";
    $result2 = mysql_query($query2) 
    or die();
    while($ans = mysql_fetch_row($result2)){
    $arr[] = $ans[0];
    }
    echo json_encode($arr);
}
?>

你能解决我的问题吗?也许我这里的代码有问题。

希望这能帮助你…:)在uiautocomplete的select属性中,将值分配给新的输入框字段

        select: function (event, ui) {
            $("#temp").val(ui.item.value);
        }

Fiddle here